40 lines
1 KiB
Text
40 lines
1 KiB
Text
with javascript_semantics
|
|
function partDiffDiff(integer n)
|
|
return (n+1)/(1+and_bits(n,1))
|
|
end function
|
|
|
|
sequence pd = {1}
|
|
function partDiff(integer n)
|
|
while n>length(pd) do
|
|
pd &= pd[$] + partDiffDiff(length(pd))
|
|
end while
|
|
return pd[max(1,n)]
|
|
end function
|
|
|
|
include mpfr.e
|
|
|
|
sequence pn = {mpz_init(1)}
|
|
function partitionsP(integer n)
|
|
mpz res = mpz_init(1)
|
|
while n>length(pn) do
|
|
integer nn = length(pn)+1
|
|
mpz psum = mpz_init(0)
|
|
for i=1 to nn do
|
|
integer pd = partDiff(i)
|
|
if pd>nn then exit end if
|
|
integer sgn = iff(remainder(i-1,4)<2 ? 1 : -1)
|
|
mpz pnmpd = pn[max(1,nn-pd)]
|
|
if sgn=-1 then
|
|
mpz_sub(psum,psum,pnmpd)
|
|
else
|
|
mpz_add(psum,psum,pnmpd)
|
|
end if
|
|
end for
|
|
pn = append(pn,psum)
|
|
end while
|
|
return pn[max(1,n)]
|
|
end function
|
|
|
|
atom t0 = time()
|
|
integer n=6666
|
|
printf(1,"p(%d) = %s (%s)\n",{n,mpz_get_str(partitionsP(n)),elapsed(time()-t0)})
|