BZOJ2956 (模积和)

2019-04-13 14:23发布

题目:2956: 模积和   题意:求∑∑((n mod i)*(m mod j))其中1<=i<=n,1<=j<=m,i≠j。然后mod 19940417
本题坑我太久啊,思路: ∑∑((n mod i) * (m mod j)) 1<=i<=n, 1<=j<=m, i≠j= ∑(n mod i) * ∑(m mod i) - ∑((n mod i) * (m mod i))= ∑(n-[n/i]*i) * ∑(m-[m/i]*i) - ∑(nm-([n/i]+[m/i])i+[n/i][m/i]*i*i) #include #include using namespace std; typedef long long LL; const LL MOD = 19940417; LL sum(LL n) { return n*(n+1)%MOD*(2*n+1)%MOD*3323403%MOD; } LL Solve(LL m, LL n) { LL ans=0,i,last; for(i=1;i<=m;i=last+1) { last=min(m,n/(n/i)); ans += (n/i)*(i+last)%MOD*(last-i+1)%MOD*9970209%MOD; ans %= MOD; } return ans; } int main() { LL n, m; cin>>n>>m; if(n