checking if a number is a prime

163 Views Asked by At

I was reading Wikipedia, and it was given that "all primes are of the form 6k ± 1" (other than 2 and 3), where k = 1,2,3,4,...

Is this statement correct? If yes, can we use this to test if a given number is a prime number? For instance, we can say that 41 is a prime number, since there exists an integer K (K >= 1), such that 6k - 1 = 41 ==> k = 7.

I am confused why this test cannot be used to test if a number is prime?

Thanks, Sekhar

2

There are 2 best solutions below

0
On

For $k\ge 1$ no prime can be of the form $6k$ (obvious), $6k+2=2(3k+1)$, $6k+3=3(2k+1)$, $6k+4=2(3k+2)$. There remains $6k+1$ and $6k+5=6(k+1)-1$.

2
On

If a number can be in the form $6k\pm1$ "CAN" be a prime number but not always. A prime number $p>3$ can be always in this form. If you want a text to know if a number is prime you can use the Wilson's theorem : $(p-1)\equiv -1\pmod p$