# Nemlit 的博客

By a konjac

### 题解 P4345 【[SHOI2015]超能粒子炮·改】

posted on 2019-09-01 08:51:15 | under 题解 |

### $Code:$

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define int long long
re int x = 0, f = 1; re char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return x * f;
}
#define p 2333
#define rep(i, s, t) for(re int i = s; i <= t; ++ i)
#define maxn 3000
int n, m, c[maxn][maxn], f[maxn][maxn], ans, k;
il int Lucas(int n, int m) {
if(!m || n == m) return 1;
if(n < m) return 0;
return Lucas(n / p, m / p) * c[n % p][m % p] % p;
}
signed main() {
c[0][0] = f[0][0] = 1;
rep(i, 1, p) {
f[i][0] = c[i][0] = c[i][i] = 1;
rep(j, 1, i - 1) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % p;
rep(j, 1, i) f[i][j] = (f[i][j - 1] + c[i][j]) % p;
}
while(T --) {
for(; k <= m - p; k += p) ans = (ans + f[n % p][n % p] * Lucas(n / p, k / p)) % p;
printf("%lld\n", (ans + Lucas(n / p, k / p) * f[n % p][min(n % p, m % p)]) % p);
}
return 0;
}

### 100分

for(; k <= m - p; k += p) ans = (ans + f[n % p][n % p] * Lucas(n / p, k / p)) % p;

$$F(i, j) = f[n\ \%\ p][n\ \%\ p] * F(\frac{n}{p}, \frac{m}{p} - 1) + Lucas(\frac{n}{p}, \frac{m}{p}) * f[n\ \%\ p][min(n\ \%\ p, m\ \%\ p)]$$

### $Code:$

#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define int long long
re int x = 0, f = 1; re char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return x * f;
}
#define p 2333
#define rep(i, s, t) for(re int i = s; i <= t; ++ i)
#define maxn 3000
int n, m, c[maxn][maxn], f[maxn][maxn];
il int Lucas(int n, int m) {
if(!m || n == m) return 1;
if(n < m) return 0;
return Lucas(n / p, m / p) * c[n % p][m % p] % p;
}
il int F(int n, int m) {
if(m == -1) return 0;
if(!m) return 1;
if(n < p) return f[n][m];
return (f[n % p][n % p] * F(n / p, m / p - 1) + Lucas(n / p, m / p) * f[n % p][min(n % p, m % p)]) % p;
}
signed main() {
c[0][0] = f[0][0] = 1;
rep(i, 1, p) {
f[i][0] = c[i][0] = c[i][i] = 1;
rep(j, 1, i - 1) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % p;
rep(j, 1, p) f[i][j] = (f[i][j - 1] + c[i][j]) % p;
}
}