Professional Documents
Culture Documents
Miller Rabin
Miller Rabin
h>
#include<stdlib.h>;
#include<time.h>;
while (b > 0)
{
if (b % 2 == 1)
{
res = (res * a) % n;
}
a = (a * a) % n;
b = b / 2;
}
return res;
}
while (u % 2 == 0)
{
t++;
u /= 2;
}
if (x == 1 || x == n - 1)
{
return 0;
}
if (x == n - 1)
{
return 0;
}
}
return 1;
}
if (n <= 1 || n % 2 == 0)
{
return 0;
}
if (witness(a, n))
{
return 0;
}
}
return 1;
}
int main()
{
int n, k;
srand(time(NULL));
if (is_prime(n, k))
{
printf("%d is prime.\n", n);
}
else
{
printf("%d is composite.\n", n);
}