Page 1 of 1

Number of ordered ways of writing n as the sum of 3 triangular numbers

Posted: Wed Apr 03, 2019 6:34 pm
by Cot-O-Bus
Hello colleagues,

I've implemented strait forward algorithm for case 3 according to page 6 On the representation of integers as sums of triangular numbers

But it produces wrong results for n = { 3, 9, 12, 18, 21, 30, 34, 39, 45, 48, 57, 59, 63, 66, 67, 75, 84, 93 }. Can somebody give me a hint what i miss from this document?

Code: Select all

R3(n)={
my( s=0 );
if( n%4==1, for( r=1, floor(n/4), s+=kronecker( r, n ) ); s*=24 );
if( n%4==3, for( r=1, floor(n/2), s+=kronecker( r, n ) ); s*=8 );
s
}

s3(n)={
   my( s=0 );
   fordiv( 8*n+3, d,
      if( issquare( d ),
         s+=R3( (8*n+3)/d )
      )
   );
   s/8
}