3340.Fox and Perfect Sets

Time Limit: 1s Memory Limit: 256MB

Fox Ciel studies number theory.She thinks a non-empty set S contains non-negative integers is perfect if and only if for any 3340_1.png (a can be equal to b), 3340_2.png. Where operation xor means exclusive or operation (http://en.wikipedia.org/wiki/Exclusive_or).Please calculate the number of perfect sets consisting of integers not greater than k. The answer can be very large, so print it modulo 1000000007 (109+7).

Input Format(From the terminal/stdin)

Input The first line contains an integer k (0 \le k \le 109).

Output Format(To the terminal/stdout)

Output Print a single integer - the number of required sets modulo 1000000007 (109+7).

Sample Input 1

Copy
1
 \n

Sample Output 1

Copy
2
 \n

Sample Input 2

Copy
2
 \n

Sample Output 2

Copy
3
 \n

Sample Input 3

Copy
3
 \n

Sample Output 3

Copy
5
 \n

Sample Input 4

Copy
4
 \n

Sample Output 4

Copy
6
 \n

Hints

In example 1, there are 2 such sets: {0} and {0, 1}. Note that {1} is not a perfect set since 1 xor 1 = 0 and {1} doesn't contain zero.In example 4, there are 6 such sets: {0}, {0, 1}, {0, 2}, {0, 3}, {0, 4} and {0, 1, 2, 3}.

Submit

请先 登录

© 2025 FAQs