题意
大意是求
思路
n项平方和求法:
1 + 4 + 9 + 16 + .... + \(n^2\)
= 1 * 1 + 2 * 2 + 3 * 3 + ... + n * n
= (1 + 2 + 3 + ... + n) + (1 * 2 + 2 * 3 + ... + (n - 1) * n)
= n * (n + 1)/ 2 + (1 * 2 * 3 + 2 * 3 * 3 + 3 * 3 * 4 + ... + 3 * (n - 1) * n) / 3
= n * (n + 1) / 2 + (1 * 2 * 3 + 2 * 3 * 4 - 1 * 2 * 3 + 3 * 4 * 5 - 2 * 3 * 4 + ... + (n - 1) * n * (n + 1)) / 3
= n * (n + 1) / 2 + (n - 1) * n * (n + 1) / 3
(1 * 2 + 2 * 3 + ... + (n - 1) * n)
= (1 * 2 * 3 + 2 * 3 * 3 + 3 * 3 * 4 + ... + 3 * (n - 1) * n) / 3
= (1 * 2 * 3 + 2 * 3 * 4 - 1 * 2 * 3 + 3 * 4 * 5 - 2 * 3 * 4 + ... + (n - 1) * n * (n + 1)) / 3
= (n - 1) * n * (n + 1) / 3
相加即可
void solve() {
LL n;
cin >> n;
LL sum = 0;
if (n % 3 == 0) {
sum = n * (n + 1) / 2 % MOD + n * (n + 1) / 3 % MOD * (n - 1) % MOD + n * (n + 1) / 3 % MOD * (n - 1) % MOD;
}else {
sum = n * (n + 1) / 2 % MOD + (n - 1) * (n + 1) / 3 % MOD * n % MOD + (n - 1) * (n + 1) / 3 % MOD * n % MOD;
}
sum = 2022 * sum % MOD;
cout << sum << endl;
}
标签:...,Demodogs,sum,Kill,LL,MOD
From: https://www.cnblogs.com/lbzbk/p/17146016.html