D. Do it Right!(2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest )

来源:互联网 发布:知乎论坛网站彭加木 编辑:程序博客网 时间:2024/04/25 03:00
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 ABand 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;}


0 0
原创粉丝点击