1

How do I find the highest power of a given prime p dividing a number N with PARI/GP?

E. g. if we have p = 7 and N = 3087 we get e = 3 with p^e | N but p^(e+1) not dividing N.

I want to avoid a full factorization of the number N.

Ystar
  • 351
  • 1
  • 3
  • 8

1 Answers1

2

Use the valuation command, like so:

valuation(3087, 7)

This does not compute the factorization of the number.

Alternately, you could write your own function:

val(n, p)=
{
  if(n==0, return(+oo));
  my(e);
  while(n%p==0,
    n /= p;
    e++
  );
  e;
}
Charles
  • 11,269
  • 13
  • 67
  • 105