06-30-2022, 01:32 PM
(06-30-2022, 12:46 PM)david_uwi Wrote: 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
That's pretty fast @david_uwi, looks like a variation on a 30 wheeler, 1.5 secs on my system, mine takes 2.5 plus but mine can factor numbers once the sieving is complete. Shall we have a look at my 2310 wheeler? ought to do much better now that I am using 0.8.2 with optimized compiler. ;-))
b = b + ...