11549 - Calculator Conundrum
Time limit: 6.000 seconds
Problem C
CALCULATOR CONUNDRUM
Alice got a hold of an old calculator that can display n digits. She was bored enough to come up with the following time waster.
She enters a number k then repeatedly squares it until the result overflows. When the result overflows, only the n most significant digits are displayed on the screen and an error flag appears. Alice can clear the error and continue squaring the displayed number. She got bored by this soon enough, but wondered:
“Given n and k , what is the largest number I can get by wasting time in this manner?”
Program Input
The first line of the input contains an integer t (1 ≤ t ≤ 200), the number of test cases. Each test case contains two integers n (1 ≤ n ≤ 9) and k (0 ≤ k < 10n ) where n is the number of digits this calculator can display k is the starting number.
Program Output
For each test case, print the maximum number that Alice can get by repeatedly squaring the starting number as described.
Sample Input & Output
INPUT
2
1 6
2 99
OUTPUT
9
99
Calgary Collegiate Programming Contest 2008
分析:
这道题目采用的是暴力法,模拟这个过程,当这个数的平方超过范围时,保留其最高位采用hash
或者是用stl的map对已经产生的数保留记录,保留这个最高位时要不断除以10;题目的时间比较
充足;
注意的问题:
平方后的结果比较大要用long long;
注意每次清空map;
code: