-
Notifications
You must be signed in to change notification settings - Fork 1
/
BoBaSoPitago.java
60 lines (57 loc) · 1.51 KB
/
BoBaSoPitago.java
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
53
54
55
56
57
58
59
60
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package codeptit;
/**
*
* @author Administrator
*/
import java.util.*;
import java.math.*;
import java.util.Scanner;
public class BoBaSoPitago {
public static boolean bSearch(long[] a, int n, long x) {
int l = 0;
int r = n - 1;
while(l <= r){
int m = (l + r)/2;
if(a[m] == x)
return true;
else if(a[m] < x)
l = m + 1;
else
r = m - 1;
}
return false;
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
int n = sc.nextInt();
long[] a = new long[n];
for(int i=0; i<n; i++){
a[i] = sc.nextLong();
a[i] *= a[i];
}
Arrays.sort(a);
int fl = 0;
for(int i=0; i<n; i++){
for(int j=i+1; j<n; j++){
if(bSearch(a, n, a[i] + a[j])){
System.out.println("YES");
fl = 1;
break;
}
}
if(fl == 1)
break;
}
if(fl == 0){
System.out.println("NO");
}
}
}
}