FIBPOL - Fibonacci Polynomial


Let F(n) be the nth member of the Fibonacci sequence:

F(0) = 0,
F(1) = 1,
F(n) = F(n-1)+F(n-2) (n > 1)

Consider the following Fibonacci polynomial:

A(x) = x F(1) + x2 F(2) + x3 F(3) + ... + xn F(n) + ... = sigma(n = 0 to infinity) xn F(n)

Amazingly,

A(1/2) = 1/2 + 1/22 + 2/23 + 3/24 + .... + F(n)/2n + ... = 2

In this problem, we only considering the non-negative-integer value of A(x). Here are some examples of A(x) for specific x.

xA(x)
00
sqrt(2)-11
1/22
[sqrt(13)-2]/33
[sqrt(89)-5]/84


Find out if x is rational with the given value of A(x)

Input

The first line contains T, the number of test cases. The next T lines contains the value of A(x).

  • 0 <= Ax <= 10^17
  • 1 <= T <= 100000

Output

  • 1 if the given Ax yields a rational x, 0 otherwise

Example

Input:
5
0
1
2
3
4

Output:
1
0
1
0
0

hide comments
[Rampage] Blue.Mary: 2016-06-10 14:48:44

Please check your test cases.


Added by:Piyush Kumar
Date:2015-09-04
Time limit:1s-3s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU JS-MONKEY SCM qobi
Resource:Project Euler