Codeforces 1151C

Analog simulation questions honestly Well, do not dwell on Sao operation, the result is become increasingly complex.
Odd and even by 2 ^ 1 ^ 0,2, ... the length of the cross, and from small to large, approach is to calculate how many odd before a number, the even number, then summed answer came out.
Then it honestly analog
Because Save, the first increase and then a modulo

#include<bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i = 0;i<int(n);i++)
typedef long long LL;
const LL mod = 1000000007;
LL l,r;
LL sov(LL x){
	LL tmp = 1,i = 0,num1 = 0,num2 = 0;
	while(x){
		if(x <= tmp){
			if(i & 1) num2 = (num2 + x) % mod;
			else num1 = (num1 + x) % mod;
			break; 
		}
		if(i & 1) num2 = (num2 + tmp) % mod;
		else num1 = (num1 + tmp) % mod;
		x = x - tmp;
		tmp <<= 1;
		i++;
	}
	return (num1 * num1 % mod + num2 * (num2 + 1) % mod + mod) %mod;
} 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>l>>r;
	cout<<(sov(r) - sov(l-1)+mod)%mod;
	return 0; 
} 

Guess you like

Origin blog.csdn.net/winhcc/article/details/89442698