Square Game
Time limit1sMemory limit1024 MB
For each query range of a sequence, find the maximum number of square operations that replace k copies of k with one k squared.
- Level
Hard8 of 10
- Topics
- Divide and conquer, Greedy, Hash map
- Solved
- No attempts yet
Problem
For an integer at least 2, an operation that replaces copies of with one is called a "square".
You are given integers . Write a program that processes the following query.
- : Find the maximum number of squares that can be performed on the sequence , and print it.
For example, in the sequence , replacing two 2s with 4 twice gives . Then the four 4s can be replaced with 16. That makes 3 squares in total, so the maximum number of squares for this sequence is 3.
Input
The first line contains , the number of test cases. The test cases follow. ()
The first line of each test case contains . ()
The next line contains integers , separated by spaces. ()
The next line contains , the number of queries. ()
Each of the next lines contains two integers and , separated by a space, which describe the -th query. ()
Output
For each test case, print "Case #" on the first line, where is the test case number.
The next lines each contain the maximum number of squares that can be performed for the corresponding query.