Light Bulb Sequence
Time limit2sMemory limit1024 MB
Counts the bulbs still on after k rounds, where round i flips every bulb whose number is divisible by i, with n at most 10k.
- Level
Hard8 of 10
- Topics
- Number theory, Math
- Solved
- No attempts yet
Problem
The stage for the next Hunger Games opening ceremony is being prepared. One of the decorations is a row of light bulbs hanging above the stage. The row has bulbs, numbered from to .
All bulbs start off. During the ceremony, the bulbs will be operated on times. During the -th operation (), the state of every bulb whose number is divisible by is flipped: an off bulb turns on, and an on bulb turns off. For a reason known only to the chief designer, does not exceed .
The chief designer wants to know how many bulbs are still on after all operations. Help him.
The number of bulbs and the number of operations are not yet final. There are possible cases, and the designer gave a list of pairs and . For each case, print the number of bulbs that are on at the end.
Input
The first line contains an integer (), the number of possible cases. Each of the next lines contains and (, , ).
Output
Print lines, each containing the answer for one case.