bridge/class-master/depend/pari/src/basemath/ifactor1.c
/* Returns 3, 5, or 7 if x is a cube (but not a 5th or 7th power),  a 5th
 * power (but not a 7th),  or a 7th power, and in this case creates the
 * base on the stack and assigns its address to *pt.  Otherwise returns 0.
 * x must be of type t_INT and positive;  this is not checked.  The *mask
 * argument tells us which things to check -- bit 0: 3rd, bit 1: 5th,
 * bit 2: 7th pwr;  set a bit to have the corresponding power examined --
 * and is updated appropriately for a possible follow-up call */
Returns 3, 5, or 7 if x is a cube (but not a 5th or 7th power),  a 5th
power (but not a 7th),  or a 7th power, and in this case creates the
base on the stack and assigns its address to *pt.  Otherwise returns 0.
x must be of type t_INT and positive;  this is not checked.  The *mask
argument tells us which things to check -- bit 0: 3rd, bit 1: 5th,
bit 2: 7th pwr;  set a bit to have the corresponding power examined
and is updated appropriately for a possible follow-up call
Returns 3 5 or 7 if x is a cube ( but not a 5th or 7th power ) a 5th power ( but not a 7th ) or a 7th power and in this case creates the base on the stack and assigns its address to * pt . Otherwise returns 0 . x must be of type t_INT and positive ; this is not checked . The * mask argument tells us which things to check -- bit 0 : 3rd bit 1 : 5th bit 2 : 7th pwr ; set a bit to have the corresponding power examined and is updated appropriately for a possible follow - up call
int
is_357_power(GEN x, GEN *pt, ulong *mask)
{
  long lx = lgefint(x);
  ulong r;
  pari_sp av;
  GEN y;
  if (!*mask) return 0; 
  if (DEBUGLEVEL>4) err_printf("OddPwrs: examining %ld-bit integer\n", expi(x));
  if (lgefint(x) == 3) {
    ulong t;
    long e = uis_357_power(x[2], &t, mask);
    if (e)
    {
      if (pt) *pt = utoi(t);
      return e;
    }
    return 0;
  }
#ifdef LONG_IS_64BIT
  r = (lx == 3)? uel(x,2): umodiu(x, 6046846918939827UL);
  if (!uis_357_powermod(r, mask)) return 0;
#else
  r = (lx == 3)? uel(x,2): umodiu(x, 211*209*61*203);
  if (!uis_357_powermod_32bit_1(r, mask)) return 0;
  r = (lx == 3)? uel(x,2): umodiu(x, 117*31*43*71);
  if (!uis_357_powermod_32bit_2(r, mask)) return 0;
#endif
  av = avma;
  while (*mask)
  {
    long e, b;
         if (*mask & 4) { b = 4; e = 7; }
    else if (*mask & 2) { b = 2; e = 5; }
    else                { b = 1; e = 3; }
    y = mpround( sqrtnr(itor(x, nbits2prec(64 + bit_accuracy(lx) / e)), e) );
    if (equalii(powiu(y,e), x))
    {
      if (!pt) { avma = av; return e; }
      avma = (pari_sp)y; *pt = gerepileuptoint(av, y);
      return e;
    }
    *mask &= ~b; 
    avma = av;
  }
  return 0;
}
int is_357_power ( GEN x , GEN * pt , ulong * mask ) { long lx = lgefint ( x ) ; ulong r ; pari_sp av ; GEN y ; if ( ! * mask ) return 0 ; if ( DEBUGLEVEL > 4 ) err_printf ( " \n " , expi ( x ) ) ; if ( lgefint ( x ) == 3 ) { ulong t ; long e = uis_357_power ( x [ 2 ] , & t , mask ) ; if ( e ) { if ( pt ) * pt = utoi ( t ) ; return e ; } return 0 ; } #ifdef LONG_IS_64BIT r = ( lx == 3 ) ? uel ( x , 2 ) : umodiu ( x , 6046846918939827UL ) ; if ( ! uis_357_powermod ( r , mask ) ) return 0 ; #else r = ( lx == 3 ) ? uel ( x , 2 ) : umodiu ( x , 211 * 209 * 61 * 203 ) ; if ( ! uis_357_powermod_32bit_1 ( r , mask ) ) return 0 ; r = ( lx == 3 ) ? uel ( x , 2 ) : umodiu ( x , 117 * 31 * 43 * 71 ) ; if ( ! uis_357_powermod_32bit_2 ( r , mask ) ) return 0 ; #endif av = avma ; while ( * mask ) { long e , b ; if ( * mask & 4 ) { b = 4 ; e = 7 ; } else if ( * mask & 2 ) { b = 2 ; e = 5 ; } else { b = 1 ; e = 3 ; } y = mpround ( sqrtnr ( itor ( x , nbits2prec ( 64 + bit_accuracy ( lx ) / e ) ) , e ) ) ; if ( equalii ( powiu ( y , e ) , x ) ) { if ( ! pt ) { avma = av ; return e ; } avma = ( pari_sp ) y ; * pt = gerepileuptoint ( av , y ) ; return e ; } * mask &= ~ b ; avma = av ; } return 0 ; }
Returns 3, 5, or 7 if x is a cube (but not a 5th or 7th power),  a 5th
 power (but not a 7th),  or a 7th power, and in this case creates the
 base on the stack and assigns its address to *pt.
Returns 3 5 or 7 if x is a cube ( but not a 5th or 7th power ) a 5th power ( but not a 7th ) or a 7th power and in this case creates the base on the stack and assigns its address to * pt .
/* useful when running in a loop */ /* priority to higher powers: if we have a 21st, it is easier to rediscover
     * that its 7th root is a cube than that its cube root is a 7th power */ /* turn the bit off */