Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
34627 | 李羽乔 | 【S】T1 | C++ | 通过 | 100 | 4 MS | 284 KB | 2740 | 2024-11-12 13:41:33 |
#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<=1e6){ int A=0,cnt=0; for(int i=0;i<=N-10;i++){ ++cnt; p[cnt]=i*i; } bool flag=true; for(int i=l;i<=r;i++){ int x=lower_bound(p+1,p+cnt+1,i)-p; if((i-p[x-1])<(p[x]-i)){ if(p[x-1]&1) A=(A+i); else A=(A-i); } else if((i-p[x-1])==(p[x]-i)){ flag=false; break; } else{ if(p[x]&1) A=(A+i); else A=(A-i); } } if(flag){ int ans=(A%md+md)%md; cout<<ans<<endl; } else{ cout<<"Game Over"<<endl; } exit(0); } 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; }