Twin Primes

Author

Eric W. Weisstein
January 15, 2007

This notebook downloaded from http://mathworld.wolfram.com/notebooks/PrimeNumbers/TwinPrimes.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/TwinPrimes.html.

©2007 Wolfram Research, Inc. except for portions noted otherwise

Enumeration

twinprimes=Select[Partition[Prime[Range[2,500]],2,1],Subtract@@#==-2&]

Average

Mean/@twinprimes

Largest Twin Prime

Print[{#,IntegerLength[n=2003663613  2^195000+#],PrimeQ[n]}//Timing]&/@{-1,1}

Large Twin Primes

large={260497545 2^6625,43690485351513 10^1995,Product[k,{k,2846,1,-4}],107570463 10^2250,663777 2^7650,75188117004 10^2298,571305 2^7701,1171452282 10^2490,459 2^8529,1706595 2^11235,4655478828 10^3429,1692923232 10^4020,6797727 2^15328,697053813 2^16352,570918348 10^5120,242206083 2^38880,835335 2^39014,361700055 2^39020,
871892617365 2^48000,
2230907354445 2^48000,2409110779845 2^60000,4648619711505 2^60000,83475759 2^64955,1693965 2^66443,665551035 2^80025,33218925 2^169690,16869987339975 2^171960};

Length[IntegerDigits[#]]&/@large//ColumnForm

Do[
Print[{i,Length[IntegerDigits[large[[i]]]],Timing[PrimeQ[large[[i]]+{-1,1}]]}],
{i,Length[large]}
]

Ruiz's Algorithm

TwinPrimeRuizQ[n_]:=Module[{i},
Sum[Floor[(n+2)/i]+Floor[n/i],{i,n}]==3+Sum[Floor[(n+1)/i]+Floor[(n-1)/i],{i,n}]
]

Select[Table[n,{n,1,1000,2}],TwinPrimeQ]

Select[Table[n,{n,1,1000,2}],TwinPrimeRuizQ]

TwinPrimeRuizQ[n_,a_]:=Module[{i},
Sum[(i^a)*(Floor[(n+2)/i]+Floor[n/i]),{i,n}]==n^a+2+Sum[i^a(Floor[(n+1)/i]+Floor[(n-1)/i]),{i,n}]
]

TwinPrimeRuizQ[n,a]

Select[Table[n,{n,1,1000,2}],TwinPrimeRuizQ[#,0]&]

Select[Table[n,{n,1,1000,2}],TwinPrimeRuizQ[#,1]&]

Select[Table[n,{n,1,1000,2}],TwinPrimeRuizQ[#,2]&]