D. Do it Right!
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Given two distinct positive integers A and B, find out if it is possible to find a third positive integer C so that a triangle with the sides A, Band C is a right triangle. Remember that a triangle is called a right triangle if one of its angles equals to 90 degrees.
Input
The first line of input contains two positive integers A and B: the lengths of the two given sides (1 ≤ A < B ≤ 100).
Output
Output "YES" if it is possible to find such an integer C, or "NO" otherwise.
Sample test(s)
input
3 4
output
YES
input
1 2
output
NO
Note
- In the first example, we can take C = 5.
- In the second example, it is impossible to find an integer C with the required property.
两种情况讨论一下就行了。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main()
{
int a,b;
while(~scanf("%d%d",&a,&b))
{
int sign=0;
int c=a*a+b*b;
int t=sqrt(c*1.0);
if(t*t==c)
sign=1;
if(a<b)
swap(a,b);
if(a>b)
{
c=a*a-b*b;
t=sqrt(c*1.0);
if(t*t==c)
sign=1;
}
if(sign)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}