-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtwosquaresornottwosquares.c
32 lines (31 loc) · 1.02 KB
/
twosquaresornottwosquares.c
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
#include<stdio.h>
#include <math.h>
int main(){
int x;
scanf("%d",&x);
int i=0;
long long n;
for(i=0;i<x;i++){
scanf("%lld",&n);
long long j=sqrt(n);
long long k=j;
long long l=0;
// for( k=0;k<=j;k++){
while(l<=j+1 || k>=l){
if(l*l>n){
printf("No\n");
break;
}else if(k*k+l*l==n){
printf("Yes\n");
break;
}else{
if(k*k+l*l<n){
l++;
}else{
k--;
}
}
}
}
return 0;
}