Miller–Rabin primality test: Difference between revisions

m
added fast gmp version
m (added fast gmp version)
Line 3,842:
?Miller_Rabin("4547337172376300111955330758342147474062293202868155909489") --1
?Miller_Rabin("4547337172376300111955330758342147474062293202868155909393") --0</lang>
 
=== gmp version ===
completes near-instantly
<lang Phix>atom t0 = time()
include mpfr.e
mpz b = mpz_init("9223372036854774808")
integer c = 0
for i=4808 to 5808 do
if mpz_probable_prime_p(b,rnd_)=1 then
printf(1," %s",{mpz_get_str(b)})
c += 1 if c=5 then printf(1,"\n") c=0 end if
end if
mpz_add_ui(b,b,1)
end for
puts(1,"\n")
b = mpz_init("4547337172376300111955330758342147474062293202868155909489")
?mpz_probable_prime_p(b,rnd_)
b = mpz_init("4547337172376300111955330758342147474062293202868155909393")
?mpz_probable_prime_p(b,rnd_)
printf(1,"%s\n",{elapsed(time()-t0)})</lang>
{{out}}
<pre>
9223372036854774893 9223372036854774917 9223372036854774937 9223372036854774959 9223372036854775057
9223372036854775073 9223372036854775097 9223372036854775139 9223372036854775159 9223372036854775181
9223372036854775259 9223372036854775279 9223372036854775291 9223372036854775337 9223372036854775351
9223372036854775399 9223372036854775417 9223372036854775421 9223372036854775433 9223372036854775507
9223372036854775549 9223372036854775643 9223372036854775783
1
0
0.0s
</pre>
 
=={{header|PHP}}==
7,796

edits