Public Function Twinprime(ByVal N As Long) As String Dim E, i, P, Q, R, S, T As Long Dim K As String K = " 3" & " 5" & vbNewLine E = 1 Q = N \ 3 + 1 For i = 1 To Q Step 2 R = i \ 16: S = base(i And 15): T = Primes(R) And S If T = 0 Then P = 3 * i + 1 + (i And 1) If P + 2 < N Then R = (i + 1) \ 16: S = base((i + 1) And 15): T = Primes(R) And S If T = 0 Then If LenB(K) < 65500 Then K = K & Space(10 - Len(P)) & P & Space(10 - Len(P + 2)) & P + 2 & vbNewLine End If E = E + 1 End If Else Exit For End If End If Next i Twinprime = K & "Total:" & E End Function
Dim E, i, P, Q, R, S, T As Long
Dim K As String K = " 3" & " 5" & vbNewLine
E = 1
Q = N \ 3 + 1
For i = 1 To Q Step 2
R = i \ 16: S = base(i And 15): T = Primes(R) And S
If T = 0 Then
P = 3 * i + 1 + (i And 1)
If P + 2 < N Then
R = (i + 1) \ 16: S = base((i + 1) And 15): T = Primes(R) And S
If T = 0 Then
If LenB(K) < 65500 Then
K = K & Space(10 - Len(P)) & P & Space(10 - Len(P + 2)) & P + 2 & vbNewLine
End If
E = E + 1
End If
Else
Exit For
End If
End If
Next i
Twinprime = K & "Total:" & E
End Function