912B.md (1802B)
1 Source: https://codeforces.com/problemset/problem/912/B 2 3 B. New Year's Eve 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness. 22 23 The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum! 24 25 A xor-sum of a sequence of integers *a*1, *a*2, ..., *a**m* is defined as the bitwise XOR of all its elements: , here  denotes the bitwise XOR operation; more about bitwise XOR can be found [here.](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) 26 27 Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than *k* candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain. 28 29 Input 30 31 The sole string contains two integers *n* and *k* (1 ≤ *k* ≤ *n* ≤ 1018). 32 33 Output 34 35 Output one number — the largest possible xor-sum. 36 37 Examples 38 39 Input 40 41 ``` 42 4 3 43 ``` 44 45 Output 46 47 ``` 48 7 49 ``` 50 51 Input 52 53 ``` 54 6 6 55 ``` 56 57 Output 58 59 ``` 60 7 61 ``` 62 63 Note 64 65 In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7. 66 67 In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.