Final answer:
The Miller-Rabin compositeness test is a probabilistic algorithm that checks if an integer N is a likely prime or composite by performing k trials with random values a within [2, N-2]. Expressing N-1 as 2^s*d, where d is odd, it uses modular exponentiation and squaring to test compositeness. The test provides a 'likely prime' or 'composite' result after iterating through k trials.
Step-by-step explanation:
The Miller-Rabin compositeness test is a probabilistic algorithm used to determine whether a given integer N is likely prime or composite. It is based on the principle that, for a prime number N, certain equalities hold for N-1 when expressed in the form of 2sd, where d is odd and s is a non-negative integer.
Here is the pseudocode for the Miller-Rabin compositeness test:
-
- Input: An odd integer N>2, number of trials k.
-
- Write N-1 as 2sd with d odd.
-
- For i=1 to k:
-
- Pick a random integer a in the range [2, N-2].
-
- Compute x = ad mod N.
-
- If x = 1 or x = N-1, continue to next iteration of the loop.
-
- For r = 0 to s-1:
-
- Compute x = x2 mod N.
-
- If x = 1, return 'composite'.
-
- If x = N-1, continue to the next iteration of the outer loop.
-
- Return 'composite'.
-
- End of outer loop: return 'likely prime'.
The test is repeated k times to reduce the probability of a false positive, that is, identifying a composite number as 'likely prime'. The Extended Riemann Hypothesis suggests a bound on k for a certain level of confidence in the result. However, for practical purposes, certain fixed values of a are often used to simplify the test.