Pythagorean triplets all test cases are not correct

question https://online.codingblocks.com/player/28486/content/4667/5167
solution https://ide.codingblocks.com/s/88506

if input is 5 then triplet should be (3,4,5)=>3, 4 or (5,12,13)=>12, 13 ?

Hello @mddanish ,
It should be 12,13.

a,b and N should be long long int.
Also, after calculating the values of a and b you need check if a * a + N * N == b*b and a>N.
If it is true then print a and b, otherwise the triplet doesn’t exist so print -1.
Hit like if you understood.

1 Like

why we are checking a>N,
if N=3
then
4 * 4 + 3 * 3 == 5 * 5 and 4>3
but if N=4
3 * 3 + 4 * 4 == 5 * 5 and 3!>4 will print -1 while triplet exists.
can u explain?

In case of N=2,
a will be 0 which is less than N.

In a triplet, N should be the smallest of the three.
3,4,5 is the triplet for N=3 and not N=4.

1 Like