diff --git a/cpp/2203/220325-CN.cpp b/cpp/2203/220325-CN.cpp new file mode 100644 index 0000000..4d23258 --- /dev/null +++ b/cpp/2203/220325-CN.cpp @@ -0,0 +1,23 @@ +#include + +class Solution { +public: + // This algorithm is far NOT optimal. + static constexpr int trailingZeroes(int n) { + // Main algorithm: 2 * 5 = 10. + // Time complexity: O(n * sqrt(n)) + int cnt2 = 0, cnt5 = 0; + for (int i = 2; i <= n; ++i) { + for (int x = i; !(x % 2); x /= 2) + ++cnt2; + for (int x = i; !(x % 5); x /= 5) + ++cnt5; + } + return std::min(cnt2, cnt5); + } +}; + +int main() { + std::cout << Solution::trailingZeroes(5); + return 0; +} diff --git a/cpp/2203/CMakeLists.txt b/cpp/2203/CMakeLists.txt index 2956dec..e01461b 100644 --- a/cpp/2203/CMakeLists.txt +++ b/cpp/2203/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2203) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2203 220325.cpp) +ADD_EXECUTABLE(2203 220325-CN.cpp)