From 5e86306f1d7e7a370038be90078ad63acf44f7fa Mon Sep 17 00:00:00 2001 From: Lam Haoyin Date: Fri, 31 Dec 2021 11:31:59 +0800 Subject: [PATCH] add: 211231-CN --- 2112/211231-CN.cpp | 31 +++++++++++++++++++++++++++++++ 2112/CMakeLists.txt | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 2112/211231-CN.cpp diff --git a/2112/211231-CN.cpp b/2112/211231-CN.cpp new file mode 100644 index 0000000..61d3a85 --- /dev/null +++ b/2112/211231-CN.cpp @@ -0,0 +1,31 @@ +#include +#include + +class Solution { +public: + static bool checkPerfectNumber(int num) { + switch (num) { + case 6: + case 28: + case 496: + case 8128: + case 33550336: + return true; + default: + return false; + } + } +}; + +int main() { + for (int i = 1; i < 100000000; ++i) { + int s = 1; + int lim = int(std::sqrt(i + 0.50)); + for (int j = 2; j <= lim; ++j) + if (i % j == 0) + s += j + i / j; + if (s == i) + std::printf("%d\n", i); + } + return 0; +} \ No newline at end of file diff --git a/2112/CMakeLists.txt b/2112/CMakeLists.txt index 4007bce..07cbf46 100644 --- a/2112/CMakeLists.txt +++ b/2112/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2112) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2112 211231.cpp) \ No newline at end of file +ADD_EXECUTABLE(2112 211231-CN.cpp) \ No newline at end of file