Googol String (Small)
InterviewTime limit5sMemory limit512 MB
Build the recursive 0/1 string defined by S with a middle 0 plus a switched reversal, then answer the Kth character for each test case.
- Level
Easy3 of 10
- Topics
- Recursion, Simulation
- Solved
- No attempts yet
Problem
A "0/1 string" is a string in which every character is either 0 or 1. Two operations can be applied to a 0/1 string.
- switch: every
0becomes1and every1becomes0. For example, "100" becomes "011". - reverse: the string is reversed. For example, "100" becomes "001".
Consider the infinite sequence of 0/1 strings defined below.
- = ""
- = "0"
- = "001"
- = "0010011"
- = "001001100011011"
- ...
- = + "0" + switch(reverse())
googol is . Find the th character of . Character positions are counted from 1.
Input
The first line contains the number of test cases, . Each of the next lines contains one integer .
Output
For each test case, print one line in the form "Case #x: y", where x is the test case number starting from 1 and y is the th character of .