powered by
Calculates the order of a prime number p in n!, i.e. the highest exponent e such that p^e|n!.
p
n!
e
p^e|n!
ordpn(p, n)
Returns the exponent e.
prime number.
natural number.
Applies the well-known formula adding terms floor(n/p^k).
floor(n/p^k)
ordpn(2, 100) #=> 97 ordpn(7, 100) #=> 16 ordpn(101, 100) #=> 0 ordpn(997, 1000) #=> 1
Run the code above in your browser using DataLab