Please help me to find the problem in this code
Pyhagoras triplet
Hello @chirag,
There are few things you should correct:
-
If Pythagoras triplet does not exists print β-1β.
Example:
N = 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. -
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
nn would be a value greater than integer range. So, it will be converted to integer value.
Hence, wrong answer.
Now the question arises.
-
how many times the loops should be iterated?
N times?
But, for large value of N, it will cause TLE. -
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.