ABC335F 题解
Register_int · · 个人记录
设
然而这种形式不太好优化。尝试用
当
当
总复杂度
AC 代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 10;
const int MAXM = 4.5e2;
const int mod = 998244353;
int n, m, a[MAXN]; ll dp[MAXN], sum[MAXM][MAXM], ans;
int main() {
scanf("%d", &n), m = sqrt(n), dp[1] = 1;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) {
if (i > 1) for (int j = 1; j <= m; j++) dp[i] = (dp[i] + sum[j][i % j]) % mod;
if (a[i] <= m) sum[a[i]][i % a[i]] = (sum[a[i]][i % a[i]] + dp[i]) % mod;
else for (int j = i + a[i]; j <= n; j += a[i]) dp[j] = (dp[j] + dp[i]) % mod;
ans = (ans + dp[i]) % mod;
}
printf("%lld", ans);
}