Rabin Miller Primality Test - Online Code


The Miller–Rabin primality test or Rabin–Miller primality test is a primality test: an algorithm which determines whether a given number is prime, similar to the Fermat primality test and the Solovay–Strassen primality test. Its original version, due to Gary L. Miller, is deterministic, but the determinism relies on the unproven generalized Riemann hypothesis; Michael O. Rabin modified it to obtain an unconditional probabilistic algorithm. This algorithm uses the same extended unconditional algorithm.

Source Code

#define COMPOSITE 0

#define PRIME 1

unsigned short mod_ex(unsigned short base, unsigned short power, unsigned short modulus) {

        unsigned long result = 1;

	int i;

	for (i=15; i>=0; i--)


		result = (
... (login or register to view full code)

To view full code, you must Login or Register, its FREE.

Hey, registering yourself just takes less than a minute and opens up a whole new GetGyan experience.


No comment yet. Be the first to post a comment.