What we can do for number having more than one pair

like for 8 we have 6,10 and 15, 17 do we have to print both ?

Hi @AjAy03, in this question we have given the constraint to be N<=10^9. We can encounter 2 pair of numbers for 1 given number only if we use an approach/algo wherein we have used loops. But if we will apply loops for a no. given 10^9 let’s say then the approach will fail. Because time limit is 1 sec.
SO pls try another approach. Try to do this question in O(1) time complexity. When you will do that you’ll successfully get answer of the doubt you asked.

Hope this helps :slight_smile:

i haven’t used any loop in my program:
#include < iostream >

using namespace std;

int main()
{
int num, num1, num2, m,n;
cin>>num;

if(num%2==0)
{
m=num/2;
n=1;
num1= (mm-nn);
num2= (mm+nn);
}
else
{
m=(num+1)/2;
n=(num-1)/2;
num1=2mn;
num2= mm+nn;
}
if(num1!=0&&num2!=0)
cout<<num1<<" “<<num2;
else
cout<<”-1";
return 0;
}

i just want to know do we have to print both the pair or just one which comes from this approch…
(add * and other also i don’t why its not showing these sign