Sexy primes: Difference between revisions

2,894 bytes added ,  2 years ago
Sexy primes in FreeBASIC
(Added XPL0 example.)
(Sexy primes in FreeBASIC)
Line 786:
Last 10: 999853 999863 999883 999907 999917 999931 999961 999979 999983 1000003
</pre>
 
 
=={{header|FreeBASIC}}==
<lang freebasic>Function isPrime(Byval ValorEval As Uinteger) As Boolean
If ValorEval < 2 Then Return False
If ValorEval Mod 2 = 0 Then Return ValorEval = 2
If ValorEval Mod 3 = 0 Then Return ValorEval = 3
Dim d As Integer = 5
While d * d <= ValorEval
If ValorEval Mod d = 0 Then Return False Else d += 2
If ValorEval Mod d = 0 Then Return False Else d += 4
Wend
Return True
End Function
 
#define maxi 1000035
Dim As Integer CU = 0, C2 = 0, C3 = 0, C4 = 0, C5 = 0, N, I, P = 0
Dim As Integer Unsexy(10), Pairs(5), Trips(5), Quads(5), Quins(5)
 
For N = maxi To 2 Step -1
If isPrime(N) Then
P += 1
If Not isPrime(N-6) And Not isPrime(N+6) Then
If CU < 10 Then Unsexy(CU) = N
CU += 1
End If
If isPrime(N-6) Then
If C2 < 5 Then Pairs(C2) = N
C2 += 1
If isPrime(N-12) Then
If C3 < 5 Then Trips(C3) = N
C3 += 1
If isPrime(N-18) Then
If C4 < 5 Then Quads(C4) = N
C4 += 1
If isPrime(N-24) Then
If C5 < 5 Then Quins(C5) = N
C5 += 1
End If
End If
End If
End If
End If
Next N
 
Print P; " primes less than"; maxi
 
Print Chr(10); C2; " pairs ending with:"
For I = 4 To 0 Step -1
Print " [" & Pairs(I)-6 & ", "& Pairs(I) & "]"
Next I
 
Print Chr(10); C3; " triplets ending with:"
For I = 4 To 0 Step -1
Print " [" & Trips(I)-12 & ", "& Trips(I)-6 & ", "& Trips(I) & "]"
Next I
 
Print Chr(10); C4; " quadruplets ending with:"
For I = 4 To 0 Step -1
Print " [" & Quads(I)-18 & ", "& Quads(I)-12 & ", "& Quads(I)-6 & ", "& Quads(I) & "]"
Next I
 
Print Chr(10); C5; " quintuplet(s) ending with:"
I = Iif(C5 > 5, 5, C5)
For I = I-1 To 0 Step -1
Print " [" & Quins(I)-24 & ", "& Quins(I)-18 & ", "& Quins(I)-12 & ", "& Quins(I)-6 & ", "& Quins(I) & "]"
Next I
 
Print Chr(10); CU; " unsexy primes ending with:"
For I = 9 To 0 Step -1
Print Unsexy(I); ",";
Next I
Print Chr(8); " "
Sleep</lang>
{{out}}
<pre> 78500 primes less than 1000035
 
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>
 
 
=={{header|Go}}==
2,156

edits