Pyhagoras triplet


Please help me to find the problem in this code

Hello @chirag,

There are few things you should correct:

  1. If Pythagoras triplet does not exists print β€œ-1”.
    Example:
    N = 2

  2. Why are you iterating i and j to 50.
    It is mentioned in the question that N <= 10^9
    So, don’t you think that your code will face for bigger values of N.

  3. As we know, multiplication of two int is always int.
    if it is coming long, than it would be converted to integer.
    (ii)+(nn)==(jj)
    for n=10^9
    n
    n would be a value greater than integer range. So, it will be converted to integer value.
    Hence, wrong answer.

Now the question arises.

  1. how many times the loops should be iterated?
    N times?
    But, for large value of N, it will cause TLE.

  2. Then, how to find this?

You have to follow a different approach in this case as the values are very big.
Read the hint given.
Refer to the following video, for better understanding:

Hope, this would help.
Give a like, if you are satisfied.