A simple way to solve Round368 Div.2 Problem C

Правка en3, от PengsenMao, 2016-08-21 12:09:23

First, suppose n is the shortest side of the triangle, m, k are other two sides. According to Pythagorean Theorem, we know n2 + m2 = k2

just do a change k2 - m2 = n2

futherly (k + m)(k - m) = n2

as we know, n2 × 1 = n2 so we can suppose that k + m = n2, k - m = 1 [because we have SPJ]

easily, we get

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,

so, we get

this is an O(1) algorithm.

So if you want to see more clearly, you can see the formual on this page. if you have some questions, i am willing to help you.:) [my english is not very good, so please pass some grammer fault.:P]

Теги math

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский PengsenMao 2016-08-21 12:09:23 230
en2 Английский PengsenMao 2016-08-21 11:54:22 312
en1 Английский PengsenMao 2016-08-21 11:49:44 893 Initial revision (published)