cf 1561D1 - Up the Strip (simplified version)
(就纯打个卡
题目链接
整除分块 + dp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
int node[N];
int n, m;
int f[N];
int s[N];
int main() {
scanf("%d%d", &n, &m);
s[1] = f[1] = 1;
for(int i = 2; i <= n; i++) {
for(int l = 2, r; l <= i; l = r+1) {
r = i / (i / l);
int k = i / l;
f[i] =(f[i] + (ll)f[k]*(r - l + 1) % m ) % m;
}
f[i] = (s[i-1] + f[i]) % m;
s[i] = (s[i-1] + f[i]) % m;
}
// for(int i = 1; i <= n; i ++) printf("%d ", f[i]); puts("");
printf("%d\n", f[n]);
return 0;
}