Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
34700 | swzzzz | 【S】T1 | C++ | 通过 | 100 | 0 MS | 264 KB | 731 | 2024-11-12 18:42:37 |
#include<bits/stdc++.h> using namespace std; #define mod 1000000007 #define ll long long ll inv(ll x){ ll y=mod-2,res=1; while (y) { if(y&1) res=(res*x)%mod; x=(x*x)%mod; y>>=1; } return res; } ll cal(ll x){ ll i2=inv(2); ll i=floor(sqrt(x)); ll l=i*i,m=l+i; ll ans=0; if(x<=m){ ans=(l+x)%mod*(x-l+1)%mod*i2%mod; }else{ ll s1=(l+m)%mod*(m-l+1)%mod*i2%mod, s2=(m+1+x)%mod*(x-m)%mod*i2%mod; ans=(s1-s2+mod)%mod; } if(i%2==0){ ans=mod-ans; } return ans; } int main(){ ll l,r; cin>>l>>r; ll ans=(cal(r)-cal(l-1)+mod)%mod; cout<<ans<<endl; return 0; }