I couldn't think anything about how to achieve it

I figured out how to check if 3 entered number is a pythagorean triplet.

But I couldn’t think of any logic about how to frame the algorithm for this q. Please help me with this quetsion.

Hello @sinchan1509_1a917d7b6cc3cbb9,

You can check my implementation for the same,

Can you please explain this code to me as I am not able to understand it

Hello @sinchan1509_1a917d7b6cc3cbb9,

  1. If n <= 2 there are no triplets.

  2. If n is even, then,
    a = (N*N)/4 -1
    b = N
    c = (N*N)/4 +1
    You can verify that a*a + b*b = c*c

  3. If N is odd, then,
    a = ((N*N) + 1)/2 - 1
    b = N
    c = ((N*N) + 1)/2
    You can verify that a*a + b*b = c*c

You can also refer from here,

ok thank you so much for help

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.