LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Contest Knowledge
Selecting an IDEInteractive TasksOutput-Only Tasks
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search FunctionsBinary Search by AnswerDivide and Conquer
Binary Numbers
Binary NumbersNumbers in codeBitwise OperationsBitmasks
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of EratosthenesModified Sieve
Data Structures
StringsStackQueueMapsSetsPriority QueueCustom Criteria for FunctionsSegment TreesFenwick TreesSparse TablesUnion FindSqrt Decomposition
Combinatorics
Addition PrincipleMultiplication PrincipleCombinatoric ObjectsInclusion Exclusion Principle
Geometry
Geometry BasicsVectorsCross and Dot ProductLinesPolygonsAnglesPoint in PolygonDistances and Intersection PointsConvex HullCircles
Recursion
PointersRecursionGenerating Combinatoric Objects
Dynamic Programming
About DPDP problemsTree DPBitmask DP
Graph Theory
GraphsDFS and BFSShortest PathsTreesTopological SortingDijkstra's AlgorithmMinimum Spanning TreesShortest Path Algorithms
Advanced Graph Theory
BiconnectivityStrongly Connected ComponentsBipartite GraphGraph FlowAugmenting PathsFlow - Minimum Cut DualityHeavy-Light DecompositionCentroid Decomposition
Advanced Data Structures
2D and 3D Segment TreesLazy PropagationImplicit Segment TreesPersistent Segment TreesLowest Common AncestorTrieBalanced Binary Search TreesMo's Algorithm

Morse Sequence

MediumProblem #48
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

You never have to write the signal down. Every digit is decided by exactly one digit that came before it.

A radio station broadcasts a signal that never stops.

The transmission starts as a single digit, 1. Every time the operator has written down a block of 2k digits, the station repeats that whole block inverted - every 1 comes back as a 0 and every 0 comes back as a 1 - and the inverted copy is appended to everything written so far.

So the transcript grows like this:

1
1 0
1 0 0 1
1 0 0 1 0 1 1 0

Given a position n, report the digit standing at that position. Positions are numbered starting from 1.

Input

First line of input will be a single integer t - the number of testcases.
Each of the next t lines contains a single integer n - the position in the signal.

Output

For every testcase print a single line with the digit (0 or 1) at position n.

Example

Input
6
1
7
8
15
1234
12345678
Output
1
1
0
0
0
1

The signal begins 1,0,0,1,0,1,1,0,…, so position 1 and position 7 hold a 1, while position 8 holds a 0.

Constraints

1≤t≤105
1≤n≤1018


This problem was adapted, with permission, from Morzeov niz, authored by Društvo matematičara Srbije and Fondacija Petlja.

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit