HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Kovrov IT > problem:


2007.B. 50270 - Bitsorting

Guest
• Discussion of problem (1)

Volume problems

• 2007.A. 50671 - Phalanx
• 2007.B. 50270 - Bitsorting
• 2007.C. 50640 - Cubes
• 2007.D. 50271 - Factorial
• 2007.E. 50663 - Lights
• 2007.F. 50690 - Parliament
• 2007.G. 50272 - Strange Numbers
• 2007.H. 50273 - Two Captains
• 2007.I. 50274 - Boundary Troops
• 2007.J. 50275 - Wedding

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Автор: Павел Кузнецов, ПГУ. Difficulty Gamma

For the set of all non-negative integers let's introduce the following order relation: let's admit that number A is less than number B in two cases:

• When the binary notation of A has fewer "ones" than B has.
• When the binary notation of A contains the same amount of "ones" that B has, and A is less than B in usual meaning.

Now sort out the set of integers, from 0 to N inclusive, in ascending order using this new order relation. Your task is to find the number, placed in position K. The numeration of the positions begins from 1.

Input
The first line of the input contains the integers N and K (0 ≤ N ≤ 1016; 1 ≤ KN+1).
Output
The output should contain one number which is the answer to the question.

Input 1 Output 1
10 7
5

Comment on the example: the integers from 0 to 10 will be sorted in the following way: 0, 1, 2, 4, 8, 3, 5, 6, 9, 10, 7.

Для отправки решений необходимо выполнить вход.

www.contester.ru