# Pythagorean triplet

Practice

Author: Aryan KD
Tester: Aryan KD
Editorialist: Aryan KD

# DIFFICULTY:

CAKEWALK, SIMPLE, EASY.

Math .

# PROBLEM:

chef has given three random number by his mother he has to identify wether the given 3 numbers are pythagorean triplet or not ? any number is pythagorean triplet if the square of addition of any two term is equal to square of 3rd term.

for example: in given number 4 5 3

4^2 + 3^2 = 5^2

in above example it is triplet

so if the given term is pythagorean triplet then print “YES” else print “NO”

# EXPLANATION:

Chef has given three random number and we have to find wether it is triplet or not
simply triplet three number is triplet if the square of biggest number is equal to sum of square of other two number
If 3 4 5 is three number is given in that biggest number is 5 so its square 5*5=25
and other two number are 3 and 4 sum of square of 3 and 4 is also equal to 25 so it is triplet there for output is YES if it is not equal hen we have to print NO
so we have to square biggest number and check wether the sum of square of other two number equal to it or no.

# SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;
//#define int long long int
void testcase()
{
int n=3;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
int k=0,p=0;
k=(a[0]*a[0])+(a[1]*a[1]);
p=a[2]*a[2];
if(k==p){
cout<<“YES”;
}
else
{
cout<<“NO”;
}

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Tester's Solution

#include<bits/stdc++.h>
using namespace std;
//#define int long long int
void testcase()
{
int n=3;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
int k=0,p=0;
k=(a[0]*a[0])+(a[1]*a[1]);
p=a[2]*a[2];
if(k==p){
cout<<“YES”;
}
else
{
cout<<“NO”;
}

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Editorialist's Solution

#include<bits/stdc++.h>
using namespace std;
//#define int long long int
void testcase()
{
int n=3;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
int k=0,p=0;
k=(a[0]*a[0])+(a[1]*a[1]);
p=a[2]*a[2];
if(k==p){
cout<<“YES”;
}
else
{
cout<<“NO”;
}

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

#include<stdio.h>
void main(){
int a,b,c;
printf(“enter the three numbers\n”);
scanf("%d %d %d",&a,&b,&c);
if(aa+bb==cc){
printf(“YES\n”);
}
else if(a
a+cc==bb){
printf(“YES\n”);
}
else if(cc+bb==a*a){
printf(“YES\n”);
}
else{
printf(“NO\n”);
}
}