naive.cpp (416B)
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 }