Rabin Miller Test

In Number Theory, I learned about the Rabin Miller Test to check if a number is prime, so I began writing a code using the test, and for some reason, the code shows that there are no prime numbers.
This is the Rabin Miller Test: http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test

And here's my code:
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
34
35
36
37
38
int gcd(int x,int y)
{
	while (1)
	{
		x=x%y;
			if (x==0)
			{
				return y;
			}
		y=y%x;
			if (y==0)
			{
				return x; 
			}
	}
}

int RabinMiller(int n)
{
	for (int a=2; a++; a<n)
	{
		if (gcd(a,n)==1)
		{
			for (int k=2; k++; k<=log(double(n-1))+1)
			{
				if (pow(double(a), (n-1)/pow(2.0,k))!=1%n)
				{
					if (pow(double(a),(n-1)/pow(2.0,k))!=-1%n)
					{
						return 0;
						break;
					}
				}
			}
		}
		return 1;
	}
}


I really appreciate the help.

Thanks!!!
Topic archived. No new replies allowed.