https://ide.codingblocks.com/s/151882 I considered all the possible cases and made all possible changes but still its showing wrong answer for 3 test cases
Wrong answer for 3 test cases
Hello @tanjuljain19,
Your code will give you wrong and multiple outputs for large inputs. You can follow the approach below for a better understanding of the question:
If n<0, n=1, n=2. Print -1 and return because squares aren’t possible for these numbers.
Now if n%2==0 that is, it’s even. We will simplify the Pythagorean equation.
a^2 + b^2 = c^2. Hence we manipulate the equation as a^2 = (c+b)(c-b).
Now if the given number is even i.e. a is even, we can express it as product of 2 even numbers say 2 and (a^2)/2.
(a^2)/2 * 2 = (c-b)(c+b)
Hence c+b = 2 and c-b = (a^2)/2.
Now solve for b and c and do similarly if given n is odd. (NOTE: I have taken a = n)