RosettaCodeData/Task/Magic-constant/Phix/magic-constant.phix

20 lines
507 B
Text
Raw Permalink Normal View History

2026-04-30 12:34:36 -04:00
with javascript_semantics
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
function magic(integer nth)
integer order = nth+2
return (order*order+1)/2 * order
end function
printf(1,"First 20 magic constants: %V\n",{apply(tagset(20),magic)})
printf(1,"1000th magic constant: %,d\n",{magic(1000)})
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
include mpfr.e
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
mpz {goal, order} = mpz_inits(2)
for i=1 to 20 do
mpz_ui_pow_ui(goal,10,i)
mpz_mul_si(order,goal,2)
mpz_nthroot(order,order,3)
mpz_add_si(order,order,1)
printf(1,"1e%d: %s\n",{i,mpz_get_str(order,10,true)})
end for