-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiller_rabin.h
33 lines (29 loc) · 941 Bytes
/
miller_rabin.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef CPP_ALGORITHM_MILLER_RABIN_H
#define CPP_ALGORITHM_MILLER_RABIN_H
namespace MillerRabin
{
/**
* \brief Compute the modular exponentiation.
* \param base base
* \param exponent exponent
* \param mod modulus
* \return result: (base^exponent) % mod
*/
auto ModularExponentiation(int base, int exponent, int mod) -> int;
/**
* \brief Test whether the number is prime.
* Witness the Fermat's theorem: a^(p-1) = 1 (mod p)
* \param exponent exponent
* \param number number
* \return whether the number is prime
*/
auto Witness(int exponent, int number) -> bool;
/**
* \brief Miller-Rabin primality test.
* \param number input number
* \param repeats repeat times to increase the probability of correctness
* \return whether the number is prime or not
*/
auto MillerRabinPrimalityTest(int number, int repeats) -> bool;
}
#endif