blackbox-1-3

Paul was the most famous character in Tekken-3. Of course he went to college and stuff. In one of the exams he wasn't able to answer a question which asked to check if a tuple of 3 non negative integers constituted a Primitive Pythagorian Triplet or not.  Paul was not able to answer it correctly and henceforth, he could not concentrate on any fight for a very long time and lost most of them. So, he decided to learn everything about Primitive Pythagorian Triplets.

Now, Paul seeks your help to determine whether a given triplet is a Primitive Pythagorian Triplet or not.

INPUT :  

The first line of the input contains the number of test cases T.
Every test case has a single line containing 3 space separated integers a,b and c.

OUTPUT :   

The output to each test case is a "YES" or a "NO".

CONSTRAINTS :   

1 ≤ T ≤ 100000

0 ≤ a,b,c ≤ 10000000

NOTE:
A primitive Pythagorean triple is one in which a, b and c are coprime.

SAMPLE INPUT
4
3 4 5
10 8 6
9 2 5
12 5 13

SAMPLE OUTPUT
YES
NO
NO
YES

Source: hackerearth | Difficulty: EASY
Tags: Mathematics


Solutions:
import fractions
import math

T=int(input())

for i in range(0,T):
    
	a,b,c=[int(x) for x in input().split(' ')]
	#print a,b,c
	if (c*c==a*a + b*b or a*a==b*b + c*c or b*b==a*a + c*c) and (fractions.gcd(a,b)==1 and fractions.gcd(b,c)==1 and fractions.gcd(c,a)==1):
		
		print('YES')
	else:
		print('NO')


import fractions
def Pythagorian_Triplet(ip):
	flag=[]
	for i in ip:
		if i[0]**2==i[1]**2+i[2]**2 or i[1]**2==i[0]**2+i[2]**2 or i[2]**2==i[0]**2+i[1]**2:
			if fractions.gcd(i[0],i[1])==1 and fractions.gcd(i[1],i[2])==1 and fractions.gcd(i[0],i[2])==1:
				flag.append(1)
			else:
				flag.append(0)
		else:
				flag.append(0)        
	return flag
t=int(input())
ips=[]
for i in range(t):
	a=input()
	a=a.split(' ')
	temp=[]
	for i in a:
		temp.append(int(i))
	ips.append(temp)
ans=Pythagorian_Triplet(ips)
for i in ans:
	if i==1:
		print("YES")
	else:
		print("NO")


from fractions import gcd
a=lambda x:int(x)**2
t=int(input())
for i in range(t):
	s=input().split()
	b=[]
	for i in range(len(s)):
		b.append(a(s[i]))
	b.sort()
	if b[0]+b[1]==b[2] and gcd(b[0],b[1])==1 and gcd(b[1],b[2])==1 and gcd(b[0],b[1])==1:
		print("YES")
	else:
		print("NO")


def gcd(x, y):
	while y:
		x, y = y, x%y
	return x

for i in range(eval(input())):
	L = (a, b, c) = list(map(int, input().split()))
	print('YES' if gcd(a,b)==gcd(a,c)==gcd(b,c)==1 and (sum([j**2 for j in L])/2)**0.5 in L else 'NO')


from fractions import gcd
t=int(input())
a=[0]*3
for i in range(t):
	n=input().split()
	a[0]=(int)(n[0])
	a[1]=(int)(n[1])
	a[2]=(int)(n[2])
	a.sort()
	#print a[0] ,a[1] ,a[2]
	if a[0]+a[1]<=a[2]:
		print("NO")
		continue
	if gcd(a[0],a[1])==1 and gcd(a[2],a[1])==1 and gcd(a[0],a[2])==1:
		if (a[0]*a[0]+a[1]*a[1])==(a[2]*a[2]):
			print("YES")
		else:
			print("NO")
			
	else:
		print("NO")
	


from fractions import gcd
t=eval(input())
while(t>0):
	s=input()
	ar=s.split()
	a=int(ar[0])
	b=int(ar[1])
	c=int(ar[2])
	if(c*c==(b*b+a*a)):
		x=gcd(a,b)
		y=gcd(b,c)
		z=gcd(c,a)
		if(x==1 and y==1 and z==1):		
			print("YES")
		else:
			print("NO")
	elif(b*b==(c*c+a*a)):
		x=gcd(a,b)
		y=gcd(b,c)
		z=gcd(c,a)
		if(x==1 and y==1 and z==1):		
			print("YES")
		else:
			print("NO")
	elif(a*a==(b*b+c*c)):
		x=gcd(a,b)
		y=gcd(b,c)
		z=gcd(c,a)
		if(x==1 and y==1 and z==1):		
			print("YES")
		else:
			print("NO")
	else:
		print("NO")
	t=t-1


import math
def gcd(a,b):
	if b==0:
		return a
	else:
		return gcd(b,a%b)
t = eval(input())
for _ in range(t):
	ar = list(map(int,input().split()))
	ar.sort()
	a,b,c = ar[0],ar[1],ar[2]
	if (math.sqrt(pow(a,2) + pow(b,2)) == c) and gcd(a,gcd(b,c)) == 1:
		print("YES")
	else:
		print("NO")


from fractions import gcd

t = int(input())
while t > 0:
	a,b,c=list(map(int,input().split()))
	if a==b or b==c or c==a:
		print('NO')
		t-=1
		continue
	r = max(a,(max(b,c)))
	
	if a>b and a>c:
		a,c=c,a
	elif b>a and b>c:
		b,c=c,a
	
	if c**2 == (a**2 + b**2):
		if gcd(a,gcd(b,c))==1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
	t-=1


def gc(a,b):
	if b==0:
		return a
	else:
		return gc(b,a%b)

import sys
t=int(input())
while t>0:
	t-=1
	a,b,c=list(map(int,input().split()))
	z=gc(a,b)
	s=gc(z,c)
	

	if (a**2 + b**2 == c**2 or a**2 + c**2 == b**2 or b**2 + c**2==a**2) and s==1 :
		print('YES')
	else:
		print('NO')


def gcd(a,b):
	if b==0:
		return a
	else:
		return gcd(b,a % b)
for p in range(eval(input())):
	a,b,c=sorted(map(int,input().split()))
	#print a,b,c
	if gcd(gcd(c,b),a)==1 and c**2==a**2+b**2:
		print("YES")
	else:
		print("NO")
	


def gcd(x, y):
	while y:
		x, y = y, x%y
	return x

for i in range(eval(input())):
	L = (a, b, c) = list(map(int, input().split()))
	print('YES' if gcd(a,b)==gcd(a,c)==gcd(b,c)==1 and pow(sum([j**2 for j in L])/2, 0.5) in L else 'NO')


t=eval(input())
for j in range(t):
	a,b,c=list(map(int,input().split()))
	x=a
	y=b
	flag=0
	while(y):
		x,y=y,x%y
	flag+=x
	y,z=b,c
	while(z):
		y,z=z,y%z
	flag+=y
	x,z=a,c
	while(x):
		z,x=x,z%x
	flag+=z
	a,b,c=a*a,b*b,c*c
	if(flag==3 and (a+b==c or b+c==a or a+c==b)):
		print("YES")
	else:
		print("NO")
		


from fractions import gcd
T = int(input())

for i in range(T): 
	X,Y,Z = [int(i) for i in input().split()]

	if (X*X+Y*Y==Z*Z and gcd(X, Y)==1 and (Z%2 and ((X%2 and Y%2==0) or (X%2==0 and Y%2)))):
		print('YES')
	elif (X*X+Z*Z==Y*Y and gcd(X,Z)==1) and (Y%2 and ((X%2 and Z%2==0) or (X%2==0 and Z%2))):
		print('YES')
	elif (Z*Z+Y*Y==X*X and gcd(Y,Z)==1)  and (X%2 and ((Z%2 and Y%2==0) or (Z%2==0 and Y%2))):
		print('YES')
	else:
		print('NO')
	


def gcd(a,b):
	if(b==0):
		return a
	else:
		return gcd(b,a%b)
def iscoprime(a,b,c):
	if(gcd(a,b)==gcd(b,c) and gcd(b,c)==gcd(c,a) and gcd(a,b)==1):
		return True
	else:
		return False
def main():
	for _ in range(eval(input())):
		to=list(map(int,input().split()))
		to.sort()
		if(to[0]**2+to[1]**2==to[2]**2 and iscoprime(to[0],to[1],to[2])):
			print("YES")
		else:
			print("NO")
			
if __name__=="__main__":
	main()


def gcd(a,b):
	t = b
	b = a % b
	if b == 0:
		return t
	else:
		return gcd(t,b)

def isCoprime(a,b,c):
	return gcd(a,b)==1 and gcd(b,c)==1 and gcd(a,c)==1

t=eval(input())
while t>0:
	t-=1
	triples=list(map(int, input().split()))[:3]
	triples.sort()
	a=triples[0]
	b=triples[1]
	c=triples[2]
	if isCoprime(a,b,c) and c*c==(b*b+a*a):
		print("YES")
	else:
		print("NO")


def gcd(i,j):
	if(j==0):
		return i
	else:
		return gcd(j,i%j)



def isCoprime(a,b,c):
	if gcd(a,b)==1 and gcd(b,c)==1 and gcd(a,c)==1:
		return True
	return False


t=eval(input())
while t>0:
	arr=[int(x) for x in input().split()]
	h=max(arr)
	arr.remove(h)
	if((h*h==(arr[0]*arr[0]+arr[1]*arr[1]))and isCoprime(h,arr[0],arr[1])):
		print('YES')
	else:
		print('NO')
	t=t-1


t=eval(input())
for j in range(t):
	a,b,c=list(map(int,input().split()))
	x=a
	y=b
	flag=0
	while(y):
		x,y=y,x%y
	flag+=x
	y,z=b,c
	while(z):
		y,z=z,y%z
	flag+=y
	x,z=a,c
	while(x):
		z,x=x,z%x
	flag+=z
	a,b,c=a*a,b*b,c*c
	if(flag==3 and (a+b==c or b+c==a or a+c==b)):
		print("YES")
	else:
		print("NO")
		


from fractions import gcd
for _ in range(eval(input())):
	alls  =  sorted(map(int, input().split()))
	a = alls[0]
	b = alls[1]
	c = alls[2]
	if a * a + b * b == c * c:
		if gcd(a,b)==1 and gcd(b, c)==1 and gcd(a, c)==1:
			print("YES")
			continue
	print("NO")    
		


from fractions import gcd
T = int(input())
for l in range (T):
	abc = [int (i) for i in input().split()]
	abc.sort()
	if (gcd(abc[2],abc[1])!=1):print ('NO')
	else:
		if (abc[2])**2 == abc[1]**2 + abc[0]**2: print ('YES')
		else: print ('NO')



def gcd(u, v):
	return gcd(v, u % v) if v else abs(u)
test = int(input())
for i in range (test):
	a,b,c = input().split(" ")
	a = int(a)
	b = int(b)
	c = int(c)
	g1 = gcd(a,b)
	g2 = gcd(b,c)
	g3 = gcd(a,c)
	#print(g1)
	#print(g2)
	#print(g3)
	if(g1!=1 or g2!=1 or g3!=1):
		print("NO")
	elif (c*c == a*a+b*b):
		print("YES")
	elif (a*a == c*c+b*b):
		print("YES")
	elif (b*b == a*a+c*c):
		print("YES")
	else:
		print("NO")


#!/usr/bin/env python
#-*- coding: utf-8 -*-

from math import factorial as f
from fractions import gcd as g

T = int (input ())
for t in range (T):
	l = [int (i) for i in input ().split ()]
	l.sort ()
	if l [0] ** 2 + l [1] ** 2 == l [2] ** 2 and g (l [0], l [1]) == 1 and g (l [1], l [2]) == 1 and g (l [0], l [2]) == 1: print("YES")
	else: print("NO")



def gcd(a,b):
	return a if (b==0) else gcd(b,a%b)
for _ in range(eval(input())):
	Numbers = sorted(map(int,input().split()))
	a,b,c=Numbers[0],Numbers[1],Numbers[2]
	print("YES" if (gcd(a,b)==1 and gcd(b,c)==1 and gcd(c,a)==1 and (a*a)+(b*b)==(c*c)) else "NO")


l = []

from fractions import gcd

for x in range(int(input())):
	l.append(sorted(list(map(int, input().split()))))
	
for tri in l:
	a = tri[0]
	b = tri[1]
	c = tri[2]
	if a**2 + b**2 == c**2 and gcd(a,b)==1 and gcd(b,c)==1 and gcd(a,c)==1:
		print('YES')
	else:
		print('NO')


def gcd(x, y):
	while y != 0:
		(x, y) = (y, x % y)
	return x
def main():
	t = int(input())
	while t>0:
		t = t-1;
		a,b,c = list(map(int,input().split()))
		if b>=a and b>=c:
			z=b;
			b=a;
			a=b;
		elif c>=a and c>=b:
			z=c;
			c=a;
			a=z;
		p=b*b + c*c;
		q=a*a;
		if p==q:
			if gcd(a,gcd(b,c))==1:
				print("YES")
			else:
				print("NO")
		else:
			print("NO")
main()    


from functools import reduce
def hcf(a, b):
	if b == 0:
		return a
	else:
		return hcf(b, a % b)


def gcd(a, b, c):
	return reduce(hcf, (a,b,c))
		
		
t = eval(input())

for y in range(t):
	a, b, c = sorted(map(int, input().split()))
	
	if (((a*a) + (b*b)) == (c*c)) and gcd(a, b, c) == 1:
		print("YES")
	else:
		print("NO")


def gcd(a, b):
	while b != 0:
		t = b
		b = a%b
		a = t
	return a

t=int(input().strip())
for x in range(t):
	a,b,c=list(map(int,input().split()))
	#print a,b,c
	flag=False
	if a>b and a>c:
		#print 'a is greatest'
		#print gcd(a,b),gcd(b,c)
		if (b**2 + c**2 == a**2) and gcd(a,b) == 1 and gcd(b,c) == 1:
			flag=True
	elif b>a and b>c:
		#print 'b is greater'
		if (a**2 + c**2 == b**2) and gcd(a,b) == 1 and gcd(b,c) == 1:
			flag=True
	else:
		#print 'c is greater'
		if b**2 + a**2 == c**2 and gcd(a,b) == 1 and gcd(b,c) == 1:
			flag=True
		
	if 	flag == True:
		print('YES')
	else:
		print('NO')


from fractions import *
for i in range(eval(input())):
	a=list(map(int,input().split()))
	a.sort()
	b=a[1]
	c=a[2]
	a=a[0]
	if a**2 + b**2 == c**2:
		if (gcd(a,b) == 1) and (gcd(b,c) == 1) and (gcd(a,c) == 1):
			print('YES')
		else:
			print('NO')
	else:
			print('NO')