First, suppose n is the shortest side of the triangle, m, k are other two sides.↵
According to Pythagorean Theorem, we know \(n^{2}+m^{2}=k^{2}\)↵
↵
just do a change \(k^2-m^2{2}-m^{2}=n^{2}\)↵
↵
futherly \((k+m)(k-m)=n^{2}\)↵
↵
as we know, \(n^{2}\times1=n^{2}\)↵
so we can suppose that \(k+m=n^{2},k-m=1\) [because we have SPJ]↵
↵
easily, we get \(k=\frac{n^{2}+1}{2},m=\frac{n^{2}-1}{2}\)↵
↵
because the side is a interger, so this solution can only be used when n is a odd.↵
↵
So how to deal with even? we find that if (k-m) is odd, the solution is suitable for odd.↵
On the other hand, we guess that if(k-m) is even, the solution is suitable for even.↵
↵
just as this, \(k+m=\frac{1}{2}n^{2},k-m=2\)↵
↵
so, we get \(k=\frac{1}{4}n^{2}+1,m=k-2\)↵
↵
this is an \(O(1)\) algorithm.↵
↵
It seems that CodeForces not support LaTex. So if you want to see more clearly, you can see the formual on this page.↵
P.S. this is my solution in chinese.↵
if you have some questions, i am willing to help you.:)↵
![ ](http://mirror.codeforces.com/predownloaded/27/48/274843051f250f16c714aefb314b4293e4ca5d58.png)↵
[my english is not very good, so please pass some grammer fault.:P]
According to Pythagorean Theorem, we know \(n^{2}+m^{2}=k^{2}\)↵
↵
just do a change \(k^
↵
futherly \((k+m)(k-m)=n^{2}\)↵
↵
as we know, \(n^{2}\times1=n^{2}\)↵
so we can suppose that \(k+m=n^{2},k-m=1\) [because we have SPJ]↵
↵
easily, we get \(k=\frac{n^{2}+1}{2},m=\frac{n^{2}-1}{2}\)↵
↵
because the side is a interger, so this solution can only be used when n is a odd.↵
↵
So how to deal with even? we find that if (k-m) is odd, the solution is suitable for odd.↵
On the other hand, we guess that if(k-m) is even, the solution is suitable for even.↵
↵
just as this, \(k+m=\frac{1}{2}n^{2},k-m=2\)↵
↵
so, we get \(k=\frac{1}{4}n^{2}+1,m=k-2\)↵
↵
this is an \(O(1)\) algorithm.↵
↵
It seems that CodeForces not support LaTex. So if you want to see more clearly, you can see the formual on this page.↵
P.S. this is my solution in chinese.↵
if you have some questions, i am willing to help you.:)↵
![ ](http://mirror.codeforces.com/predownloaded/27/48/274843051f250f16c714aefb314b4293e4ca5d58.png)↵
[my english is not very good, so please pass some grammer fault.:P]