提交时间:2024-11-12 14:56:15

运行 ID: 34660

#include<bits/stdc++.h> using namespace std; const int md = 1e9+7,N = 1e3+10; #define int long long int l,r,p[N]; int qpow(int x,int y){ int tmp=1; while(y){ if(y&1) tmp=tmp%md*x%md; x=x%md*x%md; y=y>>1; } return tmp; } signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>l>>r; if(r<=1e18){ int st=sqrt(l-1); if(st*(st+1)>(l-1)){ st--; } int num=0,ansl=0; if(st%2==0){ num=st%md*st%md; ansl=-(num%md+num%md+st%md)%md*(st+1)%md*qpow(2,md-2)%md; ansl=(ansl%md+md)%md; int z=(l-1)%md-st%md*(st+1)%md; ansl=ansl%md+(num%md+st%md+num%md+st%md+z%md+1)%md*z%md*qpow(2,md-2)%md; } else{ num=st%md*st%md; ansl=(num%md+num%md+st%md)%md*(st+1)%md*qpow(2,md-2)%md; ansl=(ansl%md+md)%md; int z=(l-1)%md-st%md*(st+1)%md; ansl=ansl%md-(num%md+st%md+num%md+st%md+z%md+1)%md*z%md*qpow(2,md-2)%md; } num=0; int ansr=0; st=sqrt(r); if(st*(st+1)>r){ st--; } if(st%2==0){ num=st%md*st%md; ansr=-(num%md+num%md+st%md)%md*(st+1)%md*qpow(2,md-2)%md; ansr=(ansr%md+md)%md; int z=r%md-st%md*(st+1)%md; ansr=ansr%md+(num%md+st%md+num%md+st%md+z%md+1)%md*z%md*qpow(2,md-2)%md; } else{ num=st%md*st%md; ansr=(num%md+num%md+st%md)*(st+1)%md*qpow(2,md-2)%md; ansr=(ansr%md+md)%md; int z=r%md-st%md*(st+1)%md; ansr=ansr%md-(num%md+st%md+num%md+st%md+z%md+1)%md*z%md*qpow(2,md-2)%md; } int tmp=ansr-ansl,md2=md; while(tmp<0){ tmp=tmp+md2; md2=md2*2; } cout<<(tmp+md)%md<<endl; } return 0; }