Getting timelimit errors

i think my code is performing too many iterations
quest link-https://online.codingblocks.com/player/16974/content/5167?s=3847
code link-https://ide.codingblocks.com/s/69547

one more thing some number have more than one triplets set like(39,52,65),(39,80,89),(39,252,255)…these are all pythagors triplets of 39 ,so do i have to print all these triplets or only one triplet will fetch the answer?

@shubhamshagy hey shubham you don’t need to use loops I am going to discuss a naive approach for this pythagorus triplet problem
take a input n
if n>0
if input n is even use this formula
x=((n x n)/4)-1;
y=((n x n)/4)+1;
if n is odd
x=(n x n-1)/2;
y=(1+n x n)/2;
else
cout<<-1;

yeah i agree that this step is fast and simple but u cannot know the formula of all problem ,so i would like to go with the logical approach,so can you plz suggest any change in my code to remove that timelimit error yet giving correct solution.

now ,talking about your solution any number we input >0,will be definitely even or odd so it will surely give output according to the formula,so in what case it will return -1?

Hey, in a lot of ad-hoc problems, You need to use the problem specific approach (like formulas and identifying patterns etc.) to come up with a fast and effective solution.

Now in this particular question, every number greater than 2 would be a part of at least one triplet…
Check this link for the proof:

Also, showing any one triplet of that particular number would do, if it is a part of more than 1 triplet.

whats wrong in this code-https://ide.codingblocks.com/s/69628

@shubhamshagy hey shubham I have corrected your code you can refer this.

Hey Shubham,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.