提交时间:2024-11-12 13:25:41

运行 ID: 34614

#include<bits/stdc++.h> #define int long long using namespace std; const int mod=1e9+7; const int Inv2=(mod+1)>>1; inline int Get(int x){ int l=1,r=1e9; while(l<r){ int mid=l+r+1>>1; if(mid*mid<=x)l=mid; else r=mid-1; } return l; } inline int F(int r){ if(!r)return 0; int t=Get(r); if(r<=t*t+t){ int LS=((t*t+r)%mod*(r%mod-t*t%mod+1)%mod*Inv2%mod+mod)%mod; return (t&1?LS:(mod-LS)%mod); } else{ int LS=t*(t+1)%mod*(2*t%mod+1)%mod*Inv2%mod; int RS=(r+t*t%mod+t+1)%mod*(((r-t*t%mod-t)%mod+mod)%mod)%mod*Inv2%mod; int ret=(LS+mod-RS)%mod; return (t&1?ret:(mod-ret)%mod); } } int l,r; int ans=0; signed main(){ #ifndef ONLINE_JUDGE freopen("alice.in","r",stdin); freopen("alice.out","w",stdout); #endif cin>>l>>r; cout<<(F(r)-F(l-1)+mod)%mod; return 0; }