ABC452E You WILL Like Sigma Problem
首先提取公因式:把
然后考虑这个
对于每个
这个复杂度是
Code
#include <bits/stdc++.h>
using namespace std;
#define int long long
using i64 = long long;
const int N = 1e6 + 10, P = 998244353;
int n, m, a[N], b[N];
i64 s[N];
signed main()
{
cin.tie(0)->ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
for (int i = 2; i <= m; i++) {
for (int j = i, l = 1; j - i <= n; j += i) {
s[l] = (s[l] + b[i]);
s[j] = (s[j] - (j - l + 1) * b[i] % P + P) % P;
s[j + 1] = (s[j + 1] + (j - l) * b[i] % P) % P;
l = j + 1;
}
}
for (int i = 1; i <= n; i++) {
s[i] += s[i - 1];
if (s[i] >= P) s[i] -= P;
}
for (int i = 1; i <= n; i++) {
s[i] += s[i - 1];
if (s[i] >= P) s[i] -= P;
}
i64 ans = 0;
for (int i = 1; i <= n; i++) ans = (ans + a[i] * s[i] % P) % P;
cout << ans;
return 0;
}