Codeforces Round #276 (Div. 2)

Source: Internet
Author: User

Codeforces Round #276 (Div. 2)
C. Bitstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Let's denote as the number of bits set ("1 'bits) in the binary representation of the non-negative integerX.

You are given multiple queries consisting of pairs of integersLAndR. For each query, findX, Such thatL? ¡U?X? ¡U?R, And is maximum possible. If there are multiple such numbers find the smallest of them.

Input

The first line contains integerNPlease specify the number of queries (1? ¡U?N? ¡U? 10000 ). <symbol · blank "http://www.bkjia.com/kf/ware/vc/" target = "_ blank" class = "keylink"> vcD4KPHA + export + bjwvZW0 + export + aTwvZW0 + LD88ZW0 + cjwvZW0 + export/odw/export/odw /PGVtPnI8L2VtPjxlbT5pPC9lbT4/odw/MTAxOCkuPC9wPgoKCgpPdXRwdXQKPHA + fill = "brush: java; "> 31 22 41 10Output

137
Note

The binary representations of numbers from 1 to 10 are listed below:

110? =? 12

210? =? 102

310? =? 112

410? =? 1002

510? =? 1012

610? =? 1102

710? =? 1112

810? =? 10002

910? =? 10012

1010? =? 10102


~Áá Ò % *************************************************************** £°



#include 
 
  #include #include 
  
   #include 
   
    using namespace std;__int64  bit[65];int main() {   bit[0]=1;    for(int i = 1; i <= 63; i++) {        bit[i] = 2*bit[i-1];    }    int n;    scanf("%d",&n);    while(n--) {         __int64 l,r;         scanf("%I64d%I64d",&l,&r);         int j;         __int64 sum = 0;         for(j = 0; sum <=r; j++)         {             sum += bit[j];         }         j--;         while(sum > r)         {             sum -= bit[j];             if(sum < l) sum += bit[j];             j--;         }        printf("%I64d\n",sum);    }    return 0;}
   
  
 


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.