PYTHTRIP - Pythagorean Triples

A Pythagorean triple (A, B, C) is defined as three positive integers that satisfy the Pythagorean Theorem: A2 + B2 = C2. Given two positive integers A and B, your task is to verify whether they are the "legs" in a Pythagorean triple, i.e. if an integer C exists such that (A, B, C) is a Pythagorean triple.

Input

The first line will contain a single integer N (0 < N <= 10000). Each of the next N lines will contain two integers A and B (0 < A, B <= 100).

Output

For each test case, output a single line. If a valid C exists, output a line containing the word YES and the value of C, separated by a space. Otherwise, output the single word NO.

Example

Input:
4
2 2
4 3
4 5
5 12

Output:
NO
YES 5
NO
YES 13

Added by:Miorel Palii
Date:2009-10-04
Time limit:1s
Source limit:4096B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 C++ 4.3.2 ERL NODEJS OBJC PERL6 SQLITE VB.NET
Resource:University of Florida Local Contest - April 13, 2009

hide comments
2015-07-15 09:20:07
tooo easy 5 lines of code :p
2012-08-02 23:37:51 Arkadiusz Bulski
I dare to challenge integrity of this one problem. Naive integers-based method does not work, while floating-point method does. This is just too weird...
2009-10-26 13:29:41 Miorel-Lucian Palii
hendrik, there are many problems for which the source limit does not prevent building look-up tables. Perhaps realizing you could do this was part of the trick?

Ajay, I agree that this is a very easy problem, but I don't think that's grounds for making it tutorial. Take for example JULKA. That's even easier than this problem, just use a language with big integer support. And what about problem ACT? If you see the trick, it's trivial. I think that the scoring method, which is based on the number of users who solved a problem, accounts for relative difficulty of problems, and I personally believe it's good to have easy problems in the classical set to encourage new programmers.

But anyway, since most people don't care one way or the other, and a few people would rather see this as a tutorial problem, here goes :)
2009-10-26 13:29:41 hendrik
If they are simple you should at least limit the code size.
For the given input there are 63*2 triples.
You dont even have to calculate anything. Add them as constants to the code and look them up. Too simple.

Last edit: 2009-10-22 19:09:17
2009-10-26 13:29:41 Ajay Nair
I dont mind the easier problems in the classical section, but hasnt the trend been off late that easier problems being shifted to tutorials ? for eg say very recently https://www.spoj.pl/problems/KZHAPPY/ was shifted , so even i would second pratiks opinion !! Well sorry but I am not really aware of the criteria for a problem being in tutorial or classical, i am just commenting on the trend that I have observed since I joined :)

Last edit: 2009-10-19 18:03:02
2009-10-26 13:29:41 Drew Saltarelli
*shrugs* If it's too easy for you, don't do it.
2009-10-26 13:29:41 Paranoid Android
To supplement Miorel's argument check out the problem MIRRORED.
2009-10-26 13:29:41 Miorel-Lucian Palii
There are easier problems in the classical section.
2009-10-26 13:29:41 .:: Pratik ::.
Please move to challenge(shortest code) or tutorial section.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.