# Codeforces 407 A. Triangle 【Codeforces Round #239 (Div. 1)】

A. Triangle
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.

Output

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.

Sample test(s)
input
1 1

output
NO

input
5 5

output
YES
2 1
5 5
-2 4

input
5 10

output
YES
-10 4
-2 -2
1 2


 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;

#define MM(a) memset(a,0,sizeof(a))

typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 3e3+5;
const int mod = 1e9+7;
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
LL gcd(LL a, LL b)
{
if(b == 0)
return a;
return gcd(b, a%b);
}
struct node
{
int x, y;
};
node p1[maxn], p2[maxn];
int main()
{
int a, b;
while(cin>>a>>b)
{
int cnt1, cnt2, cnt, j;
double tmp;
cnt1 = cnt2 = cnt = 0;
for(int i=1; i<a; i++)
{
tmp = a*a-i*i;
j = (int)sqrt(tmp);
if(i*i+j*j == a*a)
{
p1[cnt1].x = i;
p1[cnt1++].y = j;
}
}
for(int i=1; i<b; i++)
{
tmp = b*b-i*i;
j = (int)sqrt(tmp);
if(i*i+j*j == b*b)
{
p2[cnt2].x = i;
p2[cnt2++].y = j;
}
}
bool ok = false;
for(int i=0; i<cnt1; i++)
{
for(int j=0; j<cnt2; j++)
{
if(p1[i].y!=p2[j].y && p1[i].x*p2[j].x==p1[i].y*p2[j].y)
{
puts("YES");
puts("0 0");
printf("%d %d\n",-p1[i].x,p1[i].y);
printf("%d %d\n",p2[j].x,p2[j].y);
ok = true;
break;
}
}
if(ok)
break;
}
if(!ok)
puts("NO");
}
return 0;
}



#### Codeforces Round #444 (Div. 2)-贪心&尺取-Ratings and Reality Shows

2017-11-11 20:11:11

#### codeforces 788C The Great Mixing （bitset优化dp、bfs）

2017-03-31 17:17:20

#### Codeforces Round #479 (Div. 3) F - Consecutive Subsequence（思维）

2018-05-07 11:08:38

#### Codeforces Round #471 div.2 ABC题解

2018-03-24 14:16:58

#### Codeforces Round #495 (Div. 2)：D. Sonya and Matrix（暴力）

2018-07-06 13:48:23

#### Educational Codeforces Round 46 (Rated for Div. 2) A Codehorses T-shirts

2018-06-28 08:41:58

#### Codeforces Round #446 (Div. 2) D. Gluttony

2017-11-18 21:07:25

#### CF-Educational Codeforces Round 44 (Rated for Div. 2)-A-Chess Placing

2018-05-22 04:28:33

#### Codeforces Round #454 (Div. 2, based on Technocup 2018 Elimination Round 4) A-C

2017-12-24 15:34:04

#### Codeforces Round #467 (Div. 1) E：Iqea（点分治）

2018-03-05 16:49:38