Codeforces Round #239 (Div. 2)
There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.
The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.
In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.
1 1
NO
5 5
YES
2 1
5 5
-2 4
5 10
YES
-10 4
-2 -2
1 2
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <iostream> 3 #include <string.h> 4 #include <math.h> 5 #include <map> 6 #include <algorithm> 7 using namespace std; 8 int main() 9 { 10 int a,b; 11 while(cin>>a>>b) 12 { 13 int x2,y2,x3,y3; 14 int flag = 0; 15 for (int i = 1; i <= a; i++) 16 { 17 double m = sqrt(a*a-i*i); 18 y2 = (int)m; 19 if(m!=y2) 20 continue; 21 for (int j = -b; j < 0; j++) 22 { 23 m = sqrt(b*b-j*j); 24 y3 = (int)m; 25 if(m!=y3) 26 continue; 27 if(y2==y3) 28 continue; 29 if((i-j)*(i-j)+(y3-y2)*(y3-y2)==a*a+b*b) 30 { 31 x2 = i; 32 x3 = j; 33 flag = 1; 34 break; 35 } 36 } 37 if (flag) 38 break; 39 } 40 if (flag) 41 { 42 printf("YES\n"); 43 printf("0 0\n"); 44 printf("%d %d\n%d %d\n",x2,y2,x3,y3); 45 } 46 else 47 printf("NO\n"); 48 } 49 return 0; 50 }