30 lines
915 B
Text
30 lines
915 B
Text
with javascript_semantics
|
|
include mpfr.e
|
|
procedure repunit(mpz z, integer n, base=10)
|
|
mpz_set_si(z,0)
|
|
for i=1 to n do
|
|
mpz_mul_si(z,z,base)
|
|
mpz_add_si(z,z,1)
|
|
end for
|
|
end procedure
|
|
|
|
atom t0 = time()
|
|
constant {limit,blimit} = iff(platform()=JS?{400,16} -- 1.2s
|
|
:{1000,16}) -- 22s
|
|
-- :{1000,36}) -- 1 min 35s
|
|
-- :{2700,16}) -- 9 min 30s
|
|
-- :{2700,40}) -- 52 minutes and 30s
|
|
sequence primes = get_primes_le(limit)
|
|
mpz z = mpz_init()
|
|
for base=2 to blimit do
|
|
sequence rprimes = {}
|
|
for i=1 to length(primes) do
|
|
integer p = primes[i]
|
|
repunit(z,p,base)
|
|
if mpz_prime(z) then
|
|
rprimes &= p
|
|
end if
|
|
end for
|
|
printf(1,"Base %2d: %v\n", {base, rprimes})
|
|
end for
|
|
?elapsed(time()-t0)
|