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.
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.
Corresponding to each test case, in a new line, print the largest power of prime p that divides N .
1 ≤ T ≤ 100
1 ≤ N ≤ 100000
2 ≤5000 ≤p
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.