diff options
Diffstat (limited to 'code/cpp/naive.cpp')
| -rw-r--r-- | code/cpp/naive.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/code/cpp/naive.cpp b/code/cpp/naive.cpp new file mode 100644 index 0000000..ed741e6 --- /dev/null +++ b/code/cpp/naive.cpp | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | #include "bigint.h" | ||
| 2 | |||
| 3 | #include <cstdint> | ||
| 4 | #include <iostream> | ||
| 5 | |||
| 6 | constexpr BigInt N(NUMBER); | ||
| 7 | |||
| 8 | BigInt<> find_factor() { | ||
| 9 | for (BigInt i = 2; i*i < N; i += 1) | ||
| 10 | if (N % i == 0) | ||
| 11 | return i; | ||
| 12 | return -1; | ||
| 13 | } | ||
| 14 | |||
| 15 | int main() { | ||
| 16 | // N is a compile-time constant | ||
| 17 | if (auto f = find_factor(); f > 1 && f < N) | ||
| 18 | std::cout << N << " = " << f << " * " << N/f << std::endl; | ||
| 19 | else | ||
| 20 | std::cout << N << " is prime" << std::endl; | ||
| 21 | |||
| 22 | return 0; | ||
| 23 | } | ||
