ASCII Art
InterviewTime limit20sMemory limit1024 MB
Given N, find the N-th character printed by a program that prints each letter A to Z i times in round i, for i from 1 upward.
- Level
Medium4 of 10
- Topics
- Math, Binary search
- Solved
- No attempts yet
Problem
Cody-Jamal has heard that generative artificial intelligence can produce art. He is excited about the new art opportunities, but worried that human-made art may be displaced. He thinks a good compromise is to use computers to create art that humans cannot make.
Cody-Jamal is just starting with computer-generated art, so he started simple. He wants to create an immense string that shows the English alphabet in a doubly-repeated way, to represent its ubiquity and permanence.
Cody-Jamal wrote the following program:
for i = 1 to 1e100:
for letter = A to Z:
print letter i times
Here 1e100 represents the integer . For example:
- When , the program prints
ABCD....XYZ. - When , the program prints
AABBCC...XXYYZZ. - When , the program prints
AAABBBCCC...XXXYYYZZZ.
Of course, Cody-Jamal's program takes a long time to finish. Can you help him know what the -th printed letter will be without waiting for it to be printed?
Input
The first line of the input gives the number of test cases, . test cases follow.
Each test case consists of a single line with an integer .
Output
For each test case, output one line containing Case #x: y, where is the test case number (starting from 1) and is the -th character printed by Cody-Jamal's program.
Constraints
- .
Hint
The first 35 letters printed by Cody-Jamal's program are ABCDEFGHIJKLMNOPQRSTUVWXYZAABBCCDDE.... Therefore, the 5th printed character is E and the 31st is C.