diff --git a/cpp/2204/220405-CN.cpp b/cpp/2204/220405-CN.cpp new file mode 100644 index 0000000..c9a982a --- /dev/null +++ b/cpp/2204/220405-CN.cpp @@ -0,0 +1,22 @@ +#include + +class Solution { +private: + static inline const int IS_PRIME[32] = {0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1}; +public: + static int countPrimeSetBits(int left, int right) { + int ret = 0; + for (int i = left; i <= right; ++i) { + int x = 0; + for (int n = i; n; n >>= 1) + x += n & 1; + ret += IS_PRIME[x]; + } + return ret; + } +}; + +int main() { + std::printf("%d\n", Solution::countPrimeSetBits(6, 10)); + return 0; +} diff --git a/cpp/2204/CMakeLists.txt b/cpp/2204/CMakeLists.txt index 2779ee4..eccaf53 100644 --- a/cpp/2204/CMakeLists.txt +++ b/cpp/2204/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2204) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2204 220406.cpp) +ADD_EXECUTABLE(2204 220405-CN.cpp)