

 This page uses content from Wikipedia. The original article was at Sexy_prime. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)



In mathematics, sexy primes are prime numbers that differ from each other by six.

For example, the numbers 5 and 11 are both sexy primes, because 11 minus 6 is 5.

The term "sexy prime" is a pun stemming from the Latin word for six: sex.



Sexy prime pairs: Sexy prime pairs are groups of two primes that differ by 6. e.g. (5 11), (7 13), (11 17)

See sequences: OEIS:A023201 and OEIS:A046117

Sexy prime triplets: Sexy prime triplets are groups of three primes where each differs from the next by 6. e.g. (5 11 17), (7 13 19), (17 23 29)

See sequences: OEIS:A046118, OEIS:A046119 and OEIS:A046120

Sexy prime quadruplets: Sexy prime quadruplets are groups of four primes where each differs from the next by 6. e.g. (5 11 17 23), (11 17 23 29)

See sequences: OEIS:A023271, OEIS:A046122, OEIS:A046123 and OEIS:A046124

Sexy prime quintuplets: Sexy prime quintuplets are groups of five primes with a common difference of 6. One of the terms must be divisible by 5, because 5 and 6 are relatively prime. Thus, the only possible sexy prime quintuplet is (5 11 17 23 29)

Task

For each of pairs, triplets, quadruplets and quintuplets, Find and display the count of each group type of sexy primes less than one million thirty-five (1,000,035).
Display at most the last 5, less than one million thirty-five, of each sexy prime group type.
Find and display the count of the unsexy primes less than one million thirty-five.
Find and display the last 10 unsexy primes less than one million thirty-five.
Note that 1000033 SHOULD NOT be counted in the pair count. It is sexy, but not in a pair within the limit. However, it also SHOULD NOT be listed in the unsexy primes since it is sexy. 


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