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 ≤ p ≤ 5000

**Example:**

**Input:**

3

62 7

76 2

3 5

**Output:**

9

73

0

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.

saiujwal13083 | 347 |

isiddhisingh | 252 |

Abhishek_Jadhav | 243 |

_uncle_sam_ | 221 |

c_ocoooo | 217 |

saiujwal13083 | 610 |

SumitSingh27 | 466 |

c_ocoooo | 456 |

rathiarpit29 | 379 |

NaveenKumarNakka | 370 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4931 |

Quandray | 4598 |

Login to report an issue on this page.