Twin Primes
July 26, 2019
According to number theory:
m is the base of a twin-prime pair (m, m+2) if and only if 4((m−1)! + 1) == –m (mod m (m+2)).
Your task is to write a program that implements the criterion given above, then calculate the twin primes less than a thousand. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
@programmingpraxis: Not understanding the filter. According to your calculations 3 is a solution. So substituting it into the filter — 4((m−1)! + 1) == –m (mod m (m+2)) — I get 4((3−1)! + 1) == –3 (mod 3 (3+2)) —> 4(2! + 1) == -3 (mod 3 5) —> 12 == -3 (mod 3 5) —> 12 == -3 3 —> 12 == -9, which fails.
What am I missing?
@bookofstevegraham: The left-hand side of the congruence is 12, which you computed correctly. The right-hand side of the congruence is -3, which you also computed correctly. The modulus of the congruence is m * (m+2) = 3 * 5 = 15. Since 12 and -3 differ by 15, they are congruent modulo 15 and 3 is the base of the twin prime pair (3, 5).
Cannot seem to upload solution (Steve)
Klong version (Try #5)
In Python, using a “twin-wheel”. A twin can only happen at 11, 17 and 29 (repeating every 30).
And just for fun, here a “twin-wheel” for the primes 2,3,5 and 7. Using this wheel only one in seven odd numbers have to be tested.