RosettaCodeData/Task/Cuban-primes/Phix/cuban-primes.phix
2026-02-01 16:33:20 -08:00

32 lines
827 B
Text

with javascript_semantics
include mpfr.e
integer np = 0,
i = 2
mpz p3 = mpz_init(1*1*1),
i3 = mpz_init(),
p = mpz_init(),
pn = mpz_init()
printf(1,"The first 200 cuban primes are:\n")
sequence first200 = {}
atom t0 = time()
constant lim = iff(platform()=JS?10000:100000)
while np<lim do
mpz_ui_pow_ui(i3,i,3)
mpz_sub(p,i3,p3)
if mpz_prime(p) then
mpz_set(pn,p)
np += 1
if np<=200 then
first200 = append(first200,sprintf("%,9d",mpz_get_integer(pn)))
if mod(np,10)=0 then
printf(1,"%s\n",join(first200[-10..-1]))
end if
end if
end if
mpz_set(p3,i3)
i += 1
end while
printf(1,"\nThe %,dth cuban prime is %s\n",{np,mpz_get_str(pn,comma_fill:=true)})
{p3,i3,p} = mpz_free({p3,i3,p})
?elapsed(time()-t0)