bridge/class-master/depend/pari/src/basemath/arith1.c
/* disregard the sign of x, caller will take care of x < 0 */
disregard the sign of x, caller will take care of x < 0
disregard the sign of x caller will take care of x < 0
static long
Z_isanypower_aux(GEN x, GEN *pty)
{
  long ex, v, i, l, k;
  GEN y, P, E;
  ulong mask, e = 0;
  if (abscmpii(x, gen_2) < 0) return 0; 
  if (signe(x) < 0) x = negi(x);
  k = l = 1;
  P = cgetg(26 + 1, t_VECSMALL);
  E = cgetg(26 + 1, t_VECSMALL);
  for(i = 0; i < 26; i++)
  {
    ulong p = tinyprimes[i];
    int stop;
    v = Z_lvalrem_stop(&x, p, &stop);
    if (v)
    {
      P[l] = p;
      E[l] = v; l++;
      e = ugcd(e, v); if (e == 1) goto END;
    }
    if (stop) {
      if (is_pm1(x)) k = e;
      goto END;
    }
  }
  if (e)
  { 
    long v3, v5, v7;
    ulong e2 = e;
    v = u_lvalrem(e2, 2, &e2);
    if (v)
    {
      for (i = 0; i < v; i++)
      {
        if (!Z_issquareall(x, &y)) break;
        k <<= 1; x = y;
      }
    }
    mask = 0;
    v3 = u_lvalrem(e2, 3, &e2); if (v3) mask = 1;
    v5 = u_lvalrem(e2, 5, &e2); if (v5) mask |= 2;
    v7 = u_lvalrem(e2, 7, &e2); if (v7) mask |= 4;
    while ( (ex = is_357_power(x, &y, &mask)) ) {
      x = y;
      switch(ex)
      {
        case 3: k *= 3; if (--v3 == 0) mask &= ~1; break;
        case 5: k *= 5; if (--v5 == 0) mask &= ~2; break;
        case 7: k *= 7; if (--v7 == 0) mask &= ~4; break;
      }
    }
    k *= split_exponent(e2, &x);
  }
  else
    k = Z_isanypower_nosmalldiv(&x);
END:
  if (pty && k != 1)
  {
    if (e)
    { 
      y = powuu(P[1], E[1] / k);
      for (i = 2; i < l; i++) y = mulii(y, powuu(P[i], E[i] / k));
      x = equali1(x)? y: mulii(x,y);
    }
    *pty = x;
  }
  return k == 1? 0: k;
}
static long Z_isanypower_aux ( GEN x , GEN * pty ) { long ex , v , i , l , k ; GEN y , P , E ; ulong mask , e = 0 ; if ( abscmpii ( x , gen_2 ) < 0 ) return 0 ; if ( signe ( x ) < 0 ) x = negi ( x ) ; k = l = 1 ; P = cgetg ( 26 + 1 , t_VECSMALL ) ; E = cgetg ( 26 + 1 , t_VECSMALL ) ; for ( i = 0 ; i < 26 ; i ++ ) { ulong p = tinyprimes [ i ] ; int stop ; v = Z_lvalrem_stop ( & x , p , & stop ) ; if ( v ) { P [ l ] = p ; E [ l ] = v ; l ++ ; e = ugcd ( e , v ) ; if ( e == 1 ) goto END ; } if ( stop ) { if ( is_pm1 ( x ) ) k = e ; goto END ; } } if ( e ) { long v3 , v5 , v7 ; ulong e2 = e ; v = u_lvalrem ( e2 , 2 , & e2 ) ; if ( v ) { for ( i = 0 ; i < v ; i ++ ) { if ( ! Z_issquareall ( x , & y ) ) break ; k <<= 1 ; x = y ; } } mask = 0 ; v3 = u_lvalrem ( e2 , 3 , & e2 ) ; if ( v3 ) mask = 1 ; v5 = u_lvalrem ( e2 , 5 , & e2 ) ; if ( v5 ) mask |= 2 ; v7 = u_lvalrem ( e2 , 7 , & e2 ) ; if ( v7 ) mask |= 4 ; while ( ( ex = is_357_power ( x , & y , & mask ) ) ) { x = y ; switch ( ex ) { case 3 : k *= 3 ; if ( -- v3 == 0 ) mask &= ~ 1 ; break ; case 5 : k *= 5 ; if ( -- v5 == 0 ) mask &= ~ 2 ; break ; case 7 : k *= 7 ; if ( -- v7 == 0 ) mask &= ~ 4 ; break ; } } k *= split_exponent ( e2 , & x ) ; } else k = Z_isanypower_nosmalldiv ( & x ) ; END : if ( pty && k != 1 ) { if ( e ) { y = powuu ( P [ 1 ] , E [ 1 ] / k ) ; for ( i = 2 ; i < l ; i ++ ) y = mulii ( y , powuu ( P [ i ] , E [ i ] / k ) ) ; x = equali1 ( x ) ? y : mulii ( x , y ) ; } * pty = x ; } return k == 1 ? 0 : k ; }
disregard the sign of x, caller will take care of x < 0
disregard the sign of x caller will take care of x < 0
/* -1,0,1 */ /* trial division */ /* Bingo. Result divides e */ /* add missing small factors */