Sexy primes: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
(Added XPL0 example.) |
||
Line 3,059: | Line 3,059: | ||
The last 10 are: |
The last 10 are: |
||
[999853, 999863, 999883, 999907, 999917, 999931, 999961, 999979, 999983, 1000003] |
[999853, 999863, 999883, 999907, 999917, 999931, 999961, 999979, 999983, 1000003] |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<lang XPL0>func IsPrime(N); \Return 'true' if N is prime |
|||
int N, I; |
|||
[if N <= 2 then return N = 2; |
|||
if (N&1) = 0 then \even >2\ return false; |
|||
for I:= 3 to sqrt(N) do |
|||
[if rem(N/I) = 0 then return false; |
|||
I:= I+1; |
|||
]; |
|||
return true; |
|||
]; |
|||
int CU, C2, C3, C4, C5, N, I; |
|||
int Unsexy(10), Pairs(5), Trips(5), Quads(5), Quins(5); |
|||
[CU:= 0; C2:= 0; C3:= 0; C4:= 0; C5:= 0; |
|||
for N:= 1000035 downto 2 do |
|||
[if IsPrime(N) then |
|||
[if IsPrime(N-6) then |
|||
[if C2 < 5 then Pairs(C2):= N; |
|||
C2:= C2+1; |
|||
if IsPrime(N-12) then |
|||
[if C3 < 5 then Trips(C3):= N; |
|||
C3:= C3+1; |
|||
if IsPrime(N-18) then |
|||
[if C4 < 5 then Quads(C4):= N; |
|||
C4:= C4+1; |
|||
if IsPrime(N-24) then |
|||
[if C5 < 5 then Quins(C5):= N; |
|||
C5:= C5+1; |
|||
]; |
|||
]; |
|||
]; |
|||
] |
|||
else if not IsPrime(N+6) then |
|||
[if CU < 10 then Unsexy(CU):= N; |
|||
CU:= CU+1; |
|||
]; |
|||
]; |
|||
]; |
|||
IntOut(0, C2); Text(0, " pairs ending with:^m^j"); |
|||
for I:= 4 downto 0 do |
|||
[Text(0, " ["); |
|||
IntOut(0, Pairs(I)-6); Text(0, ", "); |
|||
IntOut(0, Pairs(I)); Text(0, "]^m^j"); |
|||
]; |
|||
IntOut(0, C3); Text(0, " triplets ending with:^m^j"); |
|||
for I:= 4 downto 0 do |
|||
[Text(0, " ["); |
|||
IntOut(0, Trips(I)-12); Text(0, ", "); |
|||
IntOut(0, Trips(I)-6); Text(0, ", "); |
|||
IntOut(0, Trips(I)); Text(0, "]^m^j"); |
|||
]; |
|||
IntOut(0, C4); Text(0, " quadruplets ending with:^m^j"); |
|||
for I:= 4 downto 0 do |
|||
[Text(0, " ["); |
|||
IntOut(0, Quads(I)-18); Text(0, ", "); |
|||
IntOut(0, Quads(I)-12); Text(0, ", "); |
|||
IntOut(0, Quads(I)-6); Text(0, ", "); |
|||
IntOut(0, Quads(I)); Text(0, "]^m^j"); |
|||
]; |
|||
IntOut(0, C5); Text(0, " quintuplet(s) ending with:^m^j"); |
|||
I:= if C5 > 5 then 5 else C5; |
|||
for I:= I-1 downto 0 do |
|||
[Text(0, " ["); |
|||
IntOut(0, Quins(I)-24); Text(0, ", "); |
|||
IntOut(0, Quins(I)-18); Text(0, ", "); |
|||
IntOut(0, Quins(I)-12); Text(0, ", "); |
|||
IntOut(0, Quins(I)-6); Text(0, ", "); |
|||
IntOut(0, Quins(I)); Text(0, "]^m^j"); |
|||
]; |
|||
IntOut(0, CU); Text(0, " unsexy primes ending with:^m^j"); |
|||
for I:= 9 downto 0 do |
|||
[IntOut(0, Unsexy(I)); if I then Text(0, ", ")]; |
|||
CrLf(0); |
|||
]</lang> |
|||
{{out}} |
|||
<pre> |
|||
16386 pairs ending with: |
|||
[999371, 999377] |
|||
[999431, 999437] |
|||
[999721, 999727] |
|||
[999763, 999769] |
|||
[999953, 999959] |
|||
2900 triplets ending with: |
|||
[997427, 997433, 997439] |
|||
[997541, 997547, 997553] |
|||
[998071, 998077, 998083] |
|||
[998617, 998623, 998629] |
|||
[998737, 998743, 998749] |
|||
325 quadruplets ending with: |
|||
[977351, 977357, 977363, 977369] |
|||
[983771, 983777, 983783, 983789] |
|||
[986131, 986137, 986143, 986149] |
|||
[990371, 990377, 990383, 990389] |
|||
[997091, 997097, 997103, 997109] |
|||
1 quintuplet(s) ending with: |
|||
[5, 11, 17, 23, 29] |
|||
48627 unsexy primes ending with: |
|||
999853, 999863, 999883, 999907, 999917, 999931, 999961, 999979, 999983, 1000003 |
|||
</pre> |
</pre> |
||