Under construction

Still being built. Things may change

Googol String (Small)

Interview

Time limit5sMemory limit512 MB

Summary
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 0 becomes 1 and every 1 becomes 0. 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.

  • S0S_0 = ""
  • S1S_1 = "0"
  • S2S_2 = "001"
  • S3S_3 = "0010011"
  • S4S_4 = "001001100011011"
  • ...
  • SNS_N = SN−1S_{N-1} + "0" + switch(reverse(SN−1S_{N-1}))

googol is 1010010^{100}. Find the KKth character of SgoogolS_{googol}. Character positions are counted from 1.

Input

The first line contains the number of test cases, TT. Each of the next TT lines contains one integer KK.

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 KKth character of SgoogolS_{googol}.

Constraints

  • 1≤T≤1001 \le T \le 100
  • 1≤K≤1051 \le K \le 10^5

Examples4

  1. Example 1

    Input
    4
    1
    2
    3
    10
    
    Expected output
    Case #1: 0
    Case #2: 0
    Case #3: 1
    Case #4: 0
    
  2. Example 2

    Input
    1
    1
    
    Expected output
    Case #1: 0
    
  3. Example 3

    Input
    31
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    
    Expected output
    Case #1: 0
    Case #2: 0
    Case #3: 1
    Case #4: 0
    Case #5: 0
    Case #6: 1
    Case #7: 1
    Case #8: 0
    Case #9: 0
    Case #10: 0
    Case #11: 1
    Case #12: 1
    Case #13: 0
    Case #14: 1
    Case #15: 1
    Case #16: 0
    Case #17: 0
    Case #18: 0
    Case #19: 1
    Case #20: 0
    Case #21: 0
    Case #22: 1
    Case #23: 1
    Case #24: 1
    Case #25: 0
    Case #26: 0
    Case #27: 1
    Case #28: 1
    Case #29: 0
    Case #30: 1
    Case #31: 1
    
  4. Example 4

    Input
    12
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    
    Expected output
    Case #1: 0
    Case #2: 0
    Case #3: 1
    Case #4: 0
    Case #5: 0
    Case #6: 1
    Case #7: 1
    Case #8: 0
    Case #9: 0
    Case #10: 0
    Case #11: 1
    Case #12: 1