Under construction

Still being built. Things may change

Number Tricks

Interview

Time limit1sMemory limit128 MB

Summary
For each query, count the trailing zeros of n! in base b by factoring b and finding the minimum over primes of each exponent's count in n!.
Level

Medium5 of 10

Topics
Number theory, Math, Implementation, Brute force
Solved
No attempts yet

Problem

Dora loves impressing her friends with number tricks. One of her favorite tricks is to have a friend name a number nn; Dora then tells them how many zeroes appear at the end of n!n!. Her friends are usually very impressed, because n!n! is such a large number. For example, when n=100n = 100, even though n!n! is larger than the estimated number of atoms in the universe, Dora can instantly say that n!n! ends in exactly 2424 zeroes.

Some of Dora's newest friends, however, are aliens with more or fewer than ten fingers. Like every life form she has met so far, they count in a number system that has as many digits as they have fingers. Dora wants to impress them too, but she is not sure how to adapt her trick. Can you help her?

Given a base bb and a number nn, compute how many zeroes appear at the end of n!n! when it is written in base bb. For example, take b=2b = 2 and n=5n = 5. Since 5!=120=111100025! = 120 = 1111000_2, the answer is 33.

Input

The first line contains the number of scenarios. Each of the following lines describes one scenario and contains two integers bb and nn (2≤b≤10002 \le b \le 1000, 1≤n≤1 000 0001 \le n \le 1\,000\,000), both given in base ten.

Output

For each scenario, first print a line Scenario #i:, where ii is the scenario number starting at 11. Then print a single line containing kk (in base ten), the number of trailing zeroes of n!n! when it is written in base bb. Separate consecutive scenarios with a blank line.

Examples1

  1. Example 1

    Input
    3
    2 5
    10 100
    45 10000
    
    Expected output
    Scenario #1:
    3
    
    Scenario #2:
    24
    
    Scenario #3:
    2498