bridge/class-master/depend/pari/src/basemath/trans3.c
/* as above, for ulong arguments.
 * k integer > 0, 0 <= h < k, (h,k) = 1. Returns [s1,s2] such that
 * s(h,k) = (s2 + k s1) / (12k). Requires max(h + k/2, k) < LONG_MAX
 * to avoid overflow, in particular k <= LONG_MAX * 2/3 is fine */
as above, for ulong arguments.
as above for ulong arguments .
GEN
u_sumdedekind_coprime(long h, long k)
{
  long s = 1, s1 = 0, s2 = h, p = 1, pp = 0;
  while (h) {
    long r, nexth = k % h, a = k / h; 
    if (h == 1) s2 += p * s; 
    s1 += a * s;
    s = -s;
    k = h; h = nexth;
    r = a*p + pp; pp = p; p = r; 
  }
  if (s < 0) s1 -= 3; 
  return mkvecsmall2(s1, s2);
}
GEN u_sumdedekind_coprime ( long h , long k ) { long s = 1 , s1 = 0 , s2 = h , p = 1 , pp = 0 ; while ( h ) { long r , nexth = k % h , a = k / h ; if ( h == 1 ) s2 += p * s ; s1 += a * s ; s = - s ; k = h ; h = nexth ; r = a * p + pp ; pp = p ; p = r ; } if ( s < 0 ) s1 -= 3 ; return mkvecsmall2 ( s1 , s2 ) ; }
as above, for ulong arguments.
as above for ulong arguments .
/* a >= 1, a >= 2 if h = 1 */ /* occurs exactly once, last step */ /* p >= pp >= 0 */ /* in the above computation, p increases from 1 to original k,
   * -k/2 <= s2 <= h + k/2, and |s1| <= k */ /* |s1| <= k+3 ? */ /* But in fact, |s2 + p s1| <= k^2 + 1/2 - 3k; if (s < 0), we have
   * |s2| <= k/2 and it follows that |s1| < k here as well */ /* p = k; s(h,k) = (s2 + p s1)/12p. */