1500
1510
1520 :
1530 M%=HIMEM-LOMEM-500:IFM%>39999:M%=39999
1540 T%=TIME:DIMP%M%:E%=P%+M%:!P%=2:P%!4=3:N%=5:I%=2:O%=P%+8:REPEATF%=TRUE:L%=SQRN%:C%=P%+4:REPEATV%=!C%:C%=C%+4:F%=N%MODV%:UNTILF%=0ORV%>=L%:IFF%:!O%=N%:O%=O%+4
1550 IFF%:IF((O%-P%)MOD4000)=0:PRINT;(O%-P%)DIV4;" primes generated in ";(TIME-T%)/100;"s"
1560 N%=N%+I%:I%=I%EOR6:UNTILO%>E%:T%=TIME-T%
1570 PRINT;100*M%DIVT%;" primes per second"
1580 FOR O%=0 TO M%-4 STEP 4
1590 PRINT P%!O%;
1600 IF (O% AND 31)=28:PRINT CHR$8:IF (O% AND 255)=252:IFGET
1610 NEXT:PRINT
1620 END
1630
1640
1650
1660 max%=HIMEM-LOMEM-100:IF max%>39999:max%=39999
1670 DIM primes% max%
1680 primes%!0=2
1690 primes%!4=3
1700 number%=5
1710 increment%=2
1720 offset%=8
1730 T%=TIME
1740 REPEAT
1750 prime%=TRUE
1760 limit%=SQR number%
1770 thistest%=4
1780 REPEAT
1790 test%=primes%!thistest%:thistest%=thistest%+4
1800 prime%=(number% MOD test%)<>0
1810 UNTIL prime%=0 OR test%>=limit%
1820 IF prime% THEN primes%!offset%=number%:offset%=offset%+4:PRINTnumber%
1830 number%=number%+increment%:increment%=increment% EOR 6
1840 UNTIL offset%>max%
1850 T%=TIME-T%
1860 PRINT;(max%+1)/4;" primes generated in ";T%/100;"s"
1870 PRINT;100*(max%+1)DIVT%;" primes per second"
1880 END