-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathPythagorean Triplet.cpp
52 lines (47 loc) · 1.15 KB
/
Pythagorean Triplet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
Problem Statement : https://practice.geeksforgeeks.org/problems/pythagorean-triplet/0/?track=SP-Arrays%20and%20Searching
Asked in : Amazon
Code By:
Abhinav,
CSE, NIT P
(Masters_Abh on codechef, codeforces, hackerrank and Spoj)
*/
#include <bits/stdc++.h>
using namespace std;
#define lint long long int
int main() {
lint t;
cin>>t;
while(t--){
lint n;
cin>>n;
set<lint> s;
lint a[n];
for(lint i=0;i<n;i++){
lint x;
cin>>x;
a[i]=x*x; // storing the squares of all numbers in a set.
s.insert(a[i]);
}
lint d=0;
for(lint i=0;i<n;i++){
for(lint j=i+1;j<n;j++){
if(s.find(a[i]+a[j])!=s.end()){ // Finding if sum of two squares is also present in the set to find a pythagorean triplet.
// cout<<a[i]<<" "<<a[j]<<endl;
d=1;
break;
}
}
if(d){
break;
}
}
if(d){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
}
return 0;
}