Problem Solution

1 solutions

  • 1
    @ 2024-03-12 08:56:43

    brute force approach:

    lets assume the base of a right angle triangle is B, height is h and hypotenuse is H. we know that for a right angled triangle,

    B^2 + h^2 = H^2 ......... (1)

    from this equation we can iterate over h and check if H^2 is a perfect square or not. If it is a perfect square for any h we then update our answer as (B+h+H).

    So there must be a limit for h right? lets see how far should we iterate over h for a particular B to reach the maximum answer.

    As one of the side (base) is fixed so we will try to take other sides as large as possible. But it doesnt matter how large we take the value of height, it must be smaller than hypotenuse. in other words (h<H).It can be shown that the heighest value of h can be taken as (h = H-1) for an integer base. how ?

    from the equation (1) we get,

    H^2 - h^2 = B^2 .... (2)

    from the equation above we can see that B^2 is the difference between two perfect square number. If we increase the value of H we must increase the value of h also to make the difference equal as B^2. After a certain limit H will be so large that if we take h as equal to H-1 the differenct will still be greater than B^2. So it is optimal to take h = H-1 or less.

    from equation (1)

    B^2 = H^2 - h^2
    = (H+h) (H-h)
    = (H+h) (H-H+1) [ h = H-1 , taking the highest possible value of h]
    = (H+h) [ as H is almost equal to h lets assume h==H ]
    ~ 2h

    or, 2h ~ B^2
    or, h ~ (B^2)/2

    so, here is the limit of h, we just need to iterate h from 1 to (B^2)/2 to find the maximum answer.

    time complexity O(\(B^2 * log(B^2)\))

  • 1

Information

ID
1027
Difficulty
7
Category
(None)
Tags
(None)
# Submissions
46
Accepted
8
Accepted Ratio
17%
Uploaded By