Googol String (Large)
InterviewTime limit5sMemory limit512 MB
Answer the Kth character of a recursively defined binary string for each query with K up to 10^18.
- Level
Medium5 of 10
- Topics
- Recursion, Bit manipulation
- Solved
- No attempts yet
Problem
A "0/1 string" is a string in which every character is either 0 or 1. Two operations apply 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 this infinite sequence of 0/1 strings.
- = ""
- = "0"
- = "001"
- = "0010011"
- = "001001100011011"
- ...
- = + "0" + switch(reverse())
Let . Find the th character of . 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 is the test case number starting from 1 and is the th character of .