Jump to content

Sexy primes: Difference between revisions

1,563 bytes added ,  3 years ago
no edit summary
m (Changed step to "2 * p" instead of "p" in sieve of Erathostenes.)
No edit summary
Line 1,275:
1 quintuplets, ending with: (5 11 17 23 29)
48627 unsexy, ending with: 999853 999863 999883 999907 999917 999931 999961 999979 999983 1000003</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<lang Mathematica>ClearAll[AllSublengths]
AllSublengths[l_List] := If[Length[l] > 2,
Catenate[Partition[l, #, 1] & /@ Range[2, Length[l]]]
,
{l}
]
primes = Prime[Range[PrimePi[1000035]]];
ps = Union[Intersection[primes + 6, primes] - 6, Intersection[primes - 6, primes] + 6];
a = Intersection[ps + 6, ps] - 6;
b = Intersection[ps - 6, ps] + 6;
g = Graph[DeleteDuplicates[Thread[a \[UndirectedEdge] (a + 6)]~Join~Thread[(b - 6) \[UndirectedEdge] b]]];
sp = Sort /@ ConnectedComponents[g];
sp //= SortBy[First];
sp //= Map[AllSublengths];
sp //= Catenate;
sp //= SortBy[First];
sp //= DeleteDuplicates;
sel = Select[sp, Length /* EqualTo[2]];
Length[sel]
sel[[-5 ;;]] // Column
sel = Select[sp, Length /* EqualTo[3]];
Length[sel]
sel[[-5 ;;]] // Column
sel = Select[sp, Length /* EqualTo[4]];
Length[sel]
sel[[-5 ;;]] // Column
sel = Select[sp, Length /* EqualTo[5]];
Length[sel]
sel // Column
 
Select[Complement[primes, DeleteDuplicates[Catenate@sp]][[-20 ;;]], ! (PrimeQ[# + 6] \[Or] PrimeQ[# - 6]) &][[-10 ;;]] // Column</lang>
{{out}}
<pre>16386
{999371,999377}
{999431,999437}
{999721,999727}
{999763,999769}
{999953,999959}
2900
{997427,997433,997439}
{997541,997547,997553}
{998071,998077,998083}
{998617,998623,998629}
{998737,998743,998749}
325
{977351,977357,977363,977369}
{983771,983777,983783,983789}
{986131,986137,986143,986149}
{990371,990377,990383,990389}
{997091,997097,997103,997109}
1
{5,11,17,23,29}
999853
999863
999883
999907
999917
999931
999961
999979
999983
1000003</pre>
 
=={{header|Nim}}==
1,111

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.