Computer College Undergraduate Program Design Contest (2015 ') bitwise equations

Source: Internet
Author: User
Tags bitwise
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 ...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.