D - Do it Right! Gym - 100519D

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, B and 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.

Examples
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 <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;

const int maxn = 2005;

int main() {
    int a,b;scanf("%d%d",&a,&b);
    for(int i = 1;i <= 10000;i++) {
        if(a * a + b * b == i * i) {
            printf("YES\n");
            return 0;
        }
        else if(a * a + i * i == b * b) {
            printf("YES\n");
            return 0;
        }
    }
    printf("NO\n");
    return 0;
}
原创文章 930 获赞 38 访问量 5万+

猜你喜欢

转载自blog.csdn.net/tomjobs/article/details/105759528