10001th prime: Difference between revisions

m
Line 567:
 
=={{header|QB64}}==
<lang QB64>'JRace's results:
<lang QB64>max=10001: n=1: p=0: t=Timer ' PRIMES.bas russian DANILIN
'Original version: 10001 104743 .21875
'This version: 10001 104743 .109375
<lang QB64>max = 10001: n=1: p=0: t = Timer ' PRIMES.bas russian DANILIN
While n <= max ' 10001 104743 0.35 seconds
f = 0: j = 2
pp = p^0.5 'NEW VAR: move exponentiation here, to outer loop
While f < 1
' If j >= p ^ 0.5 Then f=2 'original line
' NOTE: p does not change in this loop,
' therefore p^0.5 doesn't change;
' moving p^0.5 to the outer loop will eliminate a lot of FP math)
If j >= pp Then f=2 'new version with exponentiation relocated
If p Mod j = 0 Then f=1
j=j+1
Line 578 ⟶ 586:
p=p+1
Wend
Print n-1, p-1, Timer - t</lang>
{{out}}
<pre>10001 104743 0.3511 seconds</pre>
 
=={{header|R}}==
51

edits