영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
Problem
Mikaela studies interesting positive integers, and now wants to investigate numbers that are binary palindromes. To formally describe this, we define the following functions:
bin(n) = the binary representation of the integer n without leading zeros, reverse(s) = the string s written backwards.
An integer n is thus a binary palindrome if
bin(n) = reverse(bin(n)).
Note that a palindrome is a string that reads the same forwards and backwards.
Mikaela is particularly interested in binary palindromes that contain exactly k ones in their binary representation, and now wants to know how many such numbers exist in the interval [l, r].
Given three integers l, r, and k, determine how many integers x satisfy:
- The number x is between l and r, i.e. l ≤ x ≤ r,
- The number x is a binary palindrome,
- The binary representation of x contains exactly k ones.
Input
The input consists of a single line containing three integers l, r, k (1 ≤ l ≤ r ≤ 10^18, 1 ≤ k < 60).
Output
Print an integer: the number of integers in the interval [l, r] that are binary palindromes and have exactly k ones in their binary representation.
Scoring
Your solution will be tested on a set of test groups. To earn points for a group, you must pass all test cases in that group.
| Group | Points | Constraints |
|---|---|---|
| 1 | 20 | l,r ≤ 10^9 |
| 2 | 20 | k ≤ 4 |
| 3 | 60 | No additional constraints. |
Explanation of Samples
In sample 1, we seek numbers in the interval [7, 10] that are both binary palindromes and have exactly two ones in their binary representation. There are only 4 numbers in the interval, and their binary representations are:
7 = 111_2 (palindrome, three ones) 8 = 1000_2 (not a palindrome) 9 = 1001_2 (palindrome, two ones) 10 = 1010_2 (not a palindrome)
The only number satisfying both conditions is 9, so the answer is 1.
In sample 2, we seek numbers in the interval [1, 6] that are both binary palindromes and have exactly two ones in their binary representation. There are only 6 numbers in the interval:
1 = 1_2 (palindrome, a single one) 2 = 10_2 (not a palindrome) 3 = 11_2 (palindrome, two ones) 4 = 100_2 (not a palindrome) 5 = 101_2 (palindrome, two ones) 6 = 110_2 (not a palindrome)
The numbers satisfying both conditions are 3 and 5, so the answer is 2.
예제
예제 1
7 10 2
1
예제 2
1 6 2
2
예제 3
999 99999 6
94