Олимпиадный тренинг

Задача 38518. XOR and sum


Задача

Темы:
You are given a positive integer (\(1<=N<=10^{18}\)). Find the number of pairs of integers u and v (\(0<=u, v<=N\) ) such that there are two non-negative integers a and b satisfying \(a\ xor\ b=u\)< /span> and \(a+b=v\). Here xor denotes a bitwise exclusive OR. Because the answer can be very large, modulo \(10^9+7\).

Input
The input is a positive integer (\(1<=N<=10^{18}\)).

Imprint
Print the number of possible pairs of integers u and v (\(0<=u, v<=N\)) , modulo \(10^9+7\).
 

 

Examples
# Input Output Explanations
1 3 5 u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0)
u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2)
u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1)
u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2)
u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3)
2 1422 52277  
3 1000000000000000000 787014179