0%
题目
题目链接
码队弟弟的求和问题
题面
题解
思路
数论分块知识点
图片截取了大佬的blog
手写AC代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #include<bits/stdc++.h> using namespace std; #define ll long long const ll mod = 1e9+7; ll n,m; ll inv6;
ll qpow(ll a,ll b){ ll res = 1; while(b){ if(b&1) res = res*a%mod; a = (a*a)%mod; b>>=1; } return res; }
ll f(ll n){ return n*(n+1)%mod*(2*n+1)%mod*inv6%mod;} ll solve(ll n){ ll ans = (n*(n+1)/2%mod)*n; for(int i=1,j;i<=n;i=j+1){ j = n/(n/i); if(j>n) j=n; ans = (ans - (f(j)-f(i-1))*(n/i)%mod + mod)%mod;
} return ans; }
int main(){ ios::sync_with_stdio(false); cin.tie(0); inv6 = qpow(6,mod-2); cin>>n>>m; ll ans = solve(n)*solve(m)%mod; cout<<ans<<endl; return 0; }
|
菜鸡我踩坑
坑我35mins
1 2 3
| ll ans = (n*(n+1)/2%mod)*n;
|