Factorials and Powers
Time limit1sMemory limit128 MB
For each pair n and k, find the largest i such that n! is divisible by k^i.
- Level
Medium5 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
A war has broken out in the Land of Mathematics. The Factorial faction and the Power faction are fighting to decide who will rule the land.
The Factorial faction's renowned general trains by computing his own factorial, growing as strong as , while the Power faction's admiral prepares an exponent so as to raise himself to the -th power, growing as strong as .
At last, today is the day and clash. Admiral has trained for years to divide general down into a smaller number.
Since both have grown through training, the fight is really between and . Write a program that finds the largest such that is divisible by .
Input
The first line contains the number of test cases . ()
Each of the next lines contains two integers and separated by a space. (, )
Output
For each test case, print the largest satisfying the condition on its own line.