# Help me in solving DUPLET problem

### My issue

why n-1 and 1 is wrong ??

### My code

``````#include <bits/stdc++.h>
using namespace std;

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);

int t;
cin >> t;
while (t--) {
int n;
cin >> n;
cout << "1 " << n - 1 << '\n';
}

return 0;
}

``````

Problem Link: DUPLET Problem - CodeChef

@mdrzwn01
cozz its not fulfilling the condition
(x|y)*(x^y)=n.
the correct logic is print n and n-1,

Can u please give me any test case on which 1 and n-1 is not satisfing for any odd integer

Oohh sorry i had misread the problem statement . I thought the dot ‘.’ In the expression stands for bitwise and operator … But it was the simple product …
Thank you so much for giving ur precious time for it

1 Like

But ,why it is n & n-1? what’s the logic behind it?

@sif69
since n is an odd number taking xor of n and x-1 will make is as 1 and taking or of n and n-1 will make it as n .

See the input is an odd integer, we know all odd numbers will have 1 in its LSB and even’s will have 0 in LSB. Now, we have to perform the given on operation on two integers the output has to be the number which is given as an input. We know any number multiplied by 1 result is same number by using this, we try to make one of the expression as 1, so we choose (x^y) because we can make it 1 if we choose two consecutive numbers the reason for this is in every two adjacent numbres one is even and other is odd and they mostly differ by one bit and that one is that LSB so it result to 1. and the number is used to perform OR operation which results with greater number in that two adjacent numbers so we take num and num-1 as the required answer. Hope you understand, have a nice day. All the best😊

include <bits/stdc++.h>
using namespace std;

int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);

``````int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
cout << n << " "<< n - 1 << '\n';
}

return 0;
``````

}