108 for (uint64_t iter = 2; iter < n; iter++) {
124 std::random_device rd;
125 std::mt19937 gen(rd());
126 std::uniform_int_distribution<uint64_t> dist(2, n - 3);
127 uint64_t a = dist(gen);
129 uint64_t a = 2 + rand() % (n - 4);
139 uint64_t x = mod_pow(a, d, n);
141 if (x == 1 || x == n - 1) {
170 uint64_t x = mod_pow(a, d, n);
171 if (x == 1 || x == n - 1) {
174 for (uint64_t r = 1; r < s; r++) {
175 x = mod_mul(x, x, n);
187 if (n == 2 || n == 3) {
193 uint64_t d = n - 1, s = 0;
198 for (uint64_t i = 0; i < iters; i++) {
199 uint64_t a = rand() % (n - 3) + 2;
200 if (witness(n, d, a, s)) {
210 std::cout <<
"Primes between " << min_val <<
" and " << max_val
217 for (; min_val < max_val; min_val++) {
219 if (miller_rabin_prime(min_val, iters)) {
220 std::cout << min_val <<
" ";
228 for (uint64_t b = 2; b <= std::sqrt(n); b++) {
229 uint64_t a = std::round(std::pow(n, 1.0 / b));
231 if (std::pow(a, b) < std::numeric_limits<double>::epsilon()) {
239 bool is_coprime =
true;
240 for (uint64_t i = 2; i <= std::sqrt(r); i++) {
241 if (r % i == 0 && n % i == 0) {
248 for (uint64_t i = 0; i < std::floor(2 * std::log2(n)); i++) {
255 bool is_prime =
true;
256 for (uint64_t i = 0; i < std::floor(std::log2(n)); i++) {
299 if (n % 8 == 3 || n % 8 == 5)
304 if (a % 4 == 3 && n % 4 == 3)
329 if (p != 2 && p % 2 == 0)
332 for (uint64_t i = 0; i < iters; i++) {
334 uint64_t a = rand() % (p - 1) + 1;
335 uint64_t jacobian = (p + jacobian_number(a, p)) % p;
336 uint64_t mod = mod_pow(a, (p - 1) / 2, p);
338 if (!jacobian || mod != jacobian)
350 for (uint64_t b = 2; b < n; b++) {
354 if (mod_pow(b, n - 1, n) != 1)
411 for (uint64_t index = 2; uint64_t(index) < n; index++) {
User API for openGPMP ARITHMETIC MODULE.
int64_t op_gcd(int64_t x, int64_t y)
Find Greatest Common Divisor of 2 integers.
bool miller_rabin_prime(uint64_t n, uint64_t iters)
Modified primes algorithm.
uint64_t jacobian_number(uint64_t a, uint64_t n)
uint64_t mod_mul(uint64_t a, uint64_t b, uint64_t m)
bool carmichael_num(uint64_t n)
bool witness(uint64_t n, uint64_t d, uint64_t a, uint64_t s)
void miller_rabin(uint64_t iters, uint64_t min_val, uint64_t max_val)
Miller-Rabin driver, prints values that satisfy conditions.
uint64_t mod_pow(uint64_t a, uint64_t b, uint64_t m)
bool is_prime(uint64_t n)
Determine if an integer is prime.
bool compute_miller_rabin(uint64_t d, uint64_t n)
Algorithm determining liklihood a number is prime.
bool solovoy_strassen(uint64_t p, uint64_t iters)