[seqfan] Re: some gp/pari code in OEIS returns rationals, not integers
Richard Mathar
mathar at strw.leidenuniv.nl
Wed Mar 11 17:46:36 CET 2009
gg> From seqfan-bounces at list.seqfan.eu Wed Mar 11 15:54:31 2009
gg> Date: Wed, 11 Mar 2009 16:45:15 +0200
gg> From: Georgi Guninski <guninski at guninski.com>
gg> To: seqfan at seqfan.eu
gg> Subject: [seqfan] some gp/pari code in OEIS returns rationals, not integers
gg>
gg> some gp/pari code in OEIS returns rationals, not integers
gg>
gg> A004738 - often
We can repair (re-pari) this by either a PARI code that does not use floating
point arithmetics (preferred), or an alternative one which avoids loops and
might be quicker then if n is large:
A004738(n)={
local(nred=n-1,i=1) ;
while(nred-2*i>=0,
nred -= 2*i;
i++ ;
) ;
return(1+min(nred,2*i-nred)) ;
}
A004738alt(n)={
local(d= sqrtint(4*n-3)-1,nred) ;
if(d %2,
d--
) ;
nred=n-1-d/2*(d/2+1) ;
return(1+min(nred,d+2-nred)) ;
}
More information about the SeqFan
mailing list