TWOSQRS - Two squares or not two squares

Given integer n decide if it is possible to represent it as a sum of two squares of integers.

Input

First line of input contains one integer c <= 100 - number of test cases. Then c lines follow, each of them consisting of exactly one integer 0 <= n <= 10^12.

Output

For each test case output Yes if it is possible to represent given number as a sum of two squares and No if it is not possible.

Example

Input:
10
1
2
7
14
49
9
17
76
2888
27

Output:
Yes
Yes
No
No
Yes
Yes
Yes
No
Yes
No

Added by:gawry
Date:2004-06-29
Time limit:2s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All

hide comments
2013-01-25 08:04:00 BOND
naive fermat's won't pass...
2013-01-16 16:57:41 saket diwakar
easy one....:)
2012-12-25 16:53:30 Philipp Heeg
2888 = 2 38²
2012-12-06 16:47:53 gourav
awesome things i have learnt while doing this single question...hats off my mathematicians.. :-)
2012-11-25 01:01:38 750
2888 ?¡?¡?¡
Creo que no se puede.
2012-10-12 15:46:58 Asheesh Ranjan
<snip>
Why WA ? I cant find any cases >:(

Last edit: 2022-08-18 18:04:42
2012-09-08 18:25:11 Panagiotis Kostopanagiotis
O(K*sqrt(N)) but i get TLE error, i think it's the optimal solution :/
2012-08-14 08:30:50 dev2
how 2888 is written in form of sum of the square of two number ?plzz explain...
2012-05-18 15:42:45 Ishan Bhatt
is everyone using the prime factorization method?..mine is a O(sqrt(n)) algorithm, but still giving TLE
2012-03-21 20:38:01 Darky
I'm getting a TLE in JAVA!
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.