Problems > Prime Power in a Factorial

Prime Power in a Factorial

Difficulty: 1500 4000 ms 128 MB

number-theory

Print the exponent of prime P in the factorization of N! (the largest e with Pe | N!).

Input: one line with two integers N and P.

Output: the exponent of P in N!.

Constraints:

  • 1 ≤ N ≤ 1018
  • 2 ≤ P ≤ 106, P prime

Sample Tests

Input 1
10 2
Output 1
8
Input 2
100 5
Output 2
24

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.