Cquoj 9906 Little Girl and Maximum XOR

Source: Internet
Author: User

Little Girl and Maximum xortime limit:2000msmemory limit:262144kbthis problem would be judged on codeforces. Original ID: 276D
64-bit integer IO format: %i64d Java class name: any

A little girl loves problems on bitwise operations very much. Here ' s one of them.

You are given Integers  L  and  R . Let ' s consider the values Of   For all pairs of Integers  a  and  b Span class= "Apple-converted-space" >  ( l a b R ). Your task is to find the maximum value among all considered ones.

Expression means applying bitwise excluding or operation to integers x and y. The given operation exists in all modern programming languages, for example, in languages C+ + and Java It is represented as "^", in Pascal -as«xor».

Input

The single line contains space-separated integers  l  and   R   (1≤ l R ≤1018).

%lld specifier to read or write 64-bit integers inс++. It is preferred to use the CIN, cout streams or the %i64d specifier.

Output

In a single line print a single integer-the maximum value of pairs of integers a, b (labR).

Sample Inputinput
1 2
Output
3
Input
8 16
Output
31
Input
1 1
Output
0
1 /*2 April 22, 2016 00:05:103 ^ for XOR or Operation4 after the table can be a regular answer is either 0 or 2 n times-15 6 to get the maximum XOR value, the value must be 2 n times-17 8 that is, in the binary of L and R, the past is traversed from left to right if it encounters (2 ^ i) &l is 1, (2 ^ i) &r for 09 that is, the number of shapes such as 011111111 and 100000000 must exist between L and R. Ten  One can be described in [L, R] exists in 011111111111 and 10000000000 can obtain the maximum XOR value of 2 n times-1 A  - PS: There will be a case where L is 0 R 1 First, because L < R - */ the  -# include <iostream> -# include <cstdio> -# include <cstring> +# include <algorithm> -# include <queue> +# include <vector> A# include <cmath> at# define INF0x3f3f3f3f - using namespacestd; -  - intMainvoid) - { -     inti; in     Long LongL, R, ans; -      while(cin>>l>>R) { to         //1<<i equivalent to 2 of the i-th square +         //1000 0000 0 9th Digit 2 of 8 square 1<<8 -         //so the 64th 2 of the 63-time Square is 1<<63. the          for(i = the; I >=0; i--){ *             if((l& (1ll<<i)) ^ (r& (1ll<<i))) {//1 for int type will be converted to LL $                  Break;Panax Notoginseng             } -         } theAns = (1ll<< (i+1)) -1;//to add one to the original number and minus 1. +cout<<ans<<Endl; A     } the      +     return 0;  -}

Cquoj 9906 Little Girl and Maximum XOR

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.