atcoder#ABC252H. [ABC252Ex] K-th beautiful Necklace
[ABC252Ex] K-th beautiful Necklace
Score : points
Problem Statement
We have gemstones. The color and beauty of the -th gemstone are and , respectively. Here, the color of each gemstone is one of , and there is at least one gemstone of each color.
Out of the gemstones, we will choose with distinct colors and use them to make a necklace. (The order does not matter.) The beautifulness of the necklace will be the bitwise of the chosen gemstones.
Among all possible ways to make a necklace, find the beautifulness of the necklace made in the way with the -th greatest beautifulness. (If there are multiple ways with the same beautifulness, we count all of them.)
What is bitwise $\rm XOR$?
The bitwise of integers and , , is defined as follows:
- When is written in base two, the digit in the 's place () is if either or , but not both, has in the 's place, and otherwise.
For example, . (In base two: .)
Constraints
- There are at least ways to make a necklace.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
4 2 3
2 4
2 6
1 2
1 3
5
There are four ways to make a necklace, as follows.
- Choose the -st and -rd gemstones to make a necklace with the beautifulness of .
- Choose the -st and -th gemstones to make a necklace with the beautifulness of .
- Choose the -nd and -rd gemstones to make a necklace with the beautifulness of .
- Choose the -nd and -th gemstones to make a necklace with the beautifulness of .
Thus, the necklace with the -rd greatest beautifulness has the beautifulness of .
3 1 2
1 0
1 0
1 0
0
There are three ways to make a necklace, all of which result in the beautifulness of .
10 3 11
1 414213562373095048
1 732050807568877293
2 236067977499789696
2 449489742783178098
2 645751311064590590
2 828427124746190097
3 162277660168379331
3 316624790355399849
3 464101615137754587
3 605551275463989293
766842905529259824