Wednesday, June 27, 2018

TWOSQRS - Two squares or not two squares : Classical

#The solution in Python 3 is as follows:

def check(n):
   i=2
   while i*i<=n:
       count=0
       if n%i==0:
           while n%i==0:
               count+=1
               n//=i
           if i%4==3 and count%2!=0:
               return False
       i+=1
   return n%4!=3
for _ in range(int(input())):
    n=int(input())
    if (check(n)):
        print("Yes")
    else:
        print("No")

#Visit this link for detailed explanation

#Keep visiting for more solutions of SPOJ problems in Python 3.Thank you!!!