Bitwise Equations
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 633 accepted Submission (s): 335
Problem Description You are given two positive integers X and K. Return the k-th smallest integer Y, for positive th E following equation holds:x + Y =x | Y
Where ' | ' denotes the bitwise OR operator.
Input the ' the ' input contains an integer t (t <=) which means the number of test cases.
For each case, the there are two integers x and K (1 <= x, K <= 2000000000) in one line.
Output for each case, output one line containing the number Y.
Sample Input
3 5 1 5 5 2000000000 2000000000
Sample Output
2 18 16383165351936
always looking at once space in a daze, those who say not separate friends, turn around, strangers. Familiar, quiet, quiet, left, left, unfamiliar, unfamiliar, disappeared, disappeared, strangers.
#include <string.h> #include <iostream> using namespace std;
Long Long rets=0;
Class Jisuan {Public:long long kthplusorsolution (int, int);
string Getbin (int);
};
string jisuan::getbin (int x) {string ret= "";
if (x==0) {ret= "0";
return ret;
while (x>0) {Ret=char (x%2+ ' 0 ') +ret;
x/=2;
return ret;
Long long jisuan::kthplusorsolution (int x, int k) {string strx, strk;
Strx=getbin (x);
Strk=getbin (k);
int Lx=strx.length ()-1;
int Lk=strk.length ()-1;
String ret= "";
while (lx>=0 && lk>=0) {if (strx[lx]== ' 1 ') {ret= "0" +ret;
--LX;
else {Ret=strk[lk]+ret;
--LX;
--lk;
} while (lk>=0) Ret=strk[lk--]+ret;
for (int i=0;i< (int) ret.length (); i++) rets= (rets<<1) +ret[i]-' 0 ';
return rets;
int main () {int n,x,k; Jisuan bit;
cin>>n;
while (n--) {rets=0;
cin>>x>>k;
Bit.kthplusorsolution (X,K);
cout<<rets<<endl;
}
}
@ hold read "@☆ but beg" ❤ "Ann ★ Next time we do will be better ....
for what
this time the topic is in English .... Qaq ...