Largest power of prime
Submissions: 1143   Accuracy:

60.37%

  Difficulty: Easy   Marks: 2

Given a positive integer N and a prime p, the task is to print the largest power of prime p that divides N!. Here N! means the factorial of N = 1 x 2 x 3 . . (N-1) x N.
Note that the largest power may be 0 too.


Input:
The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of a single line containing a positive integer N and a prime p.


Output:
Corresponding to each test case, in a new line, print the largest power of prime p that divides N .


Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 100000

2 ≤5000 ≤p

Example:
Input
3
62 7
76 2
3 5

Output
9
73
0

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Hemang Sarkar


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.