链接:https://ac.nowcoder.com/acm/contest/338/K
来源:牛客网
Consider the right-angled triangles with sides of integral length.
There are several test cases. The first line contains an integer T(1≤T≤1,000), T is the number of test cases.
The following T lines contain T test cases, each line contains one test case. For each test case, there is an integer : c, the length of hypotenuse.(1≤c≤45,000).
For each case, output Yes if it can construct a right triangle with given hypotenuse c and sides of integral length , No otherwise.
Yes No Yes Yes
优化一下就可以了
简单题
#include<stdio.h> #include<math.h> int main() { int t; scanf("%d",&t); while(t--) { int n; int flag = 0; scanf("%d",&n); for(int i = 1; i <= 45000&&i!=n; i++) { double sum = sqrt(n*n - i*i); // printf("%lf ",sum); if(sum - (int)sum < 0.000001) { flag = 1; break; //printf("YES\n"); } } // if(flag==1) // break; if(flag == 1) printf("Yes\n"); else printf("No\n"); } }
原文:https://www.cnblogs.com/DWVictor/p/10230006.html