Order in Faculty

Share:

Description

Calculates the order of a prime number p in n!, i.e. the highest exponent e such that p^e|n!.

Usage

1
ordpn(p, n)

Arguments

p

prime number.

n

natural number.

Details

Applies the well-known formula adding terms floor(n/p^k).

Value

Returns the exponent e.

Examples

1
2
3
4
  ordpn(2, 100)         #=> 97
  ordpn(7, 100)         #=> 16
  ordpn(101, 100)       #=>  0
  ordpn(997, 1000)      #=>  1