diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-02-26 17:12:06 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-02-26 17:12:06 +0100 |
| commit | 7f1b8a358515b45d717c3c4b5baf2fbc0f568170 (patch) | |
| tree | 3e51ad948d132ccad19da053bb083d8b760b4ec2 /code/cpp/naive.cpp | |
| download | ecm-7f1b8a358515b45d717c3c4b5baf2fbc0f568170.tar.gz ecm-7f1b8a358515b45d717c3c4b5baf2fbc0f568170.zip | |
Initial commit
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 | } | ||
