06-30-2022, 12:46 PM
Here's one that I wrote for QB4.5 (amazingly you can go up to 100 million despite the memory restrictions).
Code: (Select All)
Rem finding primes to 100 million!!!
TT = Timer
DefLng I-N
N = 3226000
Dim A(0 To N) As Long
Dim B(0 To 30) As Long
B(0) = 1
For I = 1 To 30
B(I) = B(I - 1) + B(I - 1)
Next I
For J = 2 To 5000
J1 = J \ 31: J2 = J Mod 31
If (A(J1) And B(J2)) = 0 Then
K1 = J + J - 1
K2 = K1 * J - K1 + J
For I = K2 To 50000000 Step K1
I1 = I \ 31: I2 = I Mod 31
A(I1) = (A(I1) Or B(I2))
Next I
End If
Next J
Rem *** End of main routine - Printout starts here ***
'PRINT " 2 ";
For I = 2 To 50000000
I1 = I \ 31: I2 = I Mod 31
L = A(I1) And B(I2)
If L = 0 Then
'PRINT I + I - 1; 'unrem to print
L1 = L1 + 1
End If
Next I
Print "Number of primes to 100M = "; L1 + 1; Timer - TT