Pagini recente » Cod sursa (job #2514230) | Cod sursa (job #3278338) | Cod sursa (job #3278256) | Cod sursa (job #3278301) | Cod sursa (job #2514270)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("permutari2.in");
ofstream fout("permutari2.out");
const int N = 309, MOD = 10007;
int n;
int fact[N];
int pt1[N];
int* solve(int k) {
if (k == 1)
return pt1;
int eu[N];
for (int i = 1; i <= n; ++i)
eu[i] = 0;
if (k&1) {
int *ans = solve(k - 1);
for (int i = 1; i <= n; ++i)
for (int j = 1; j + i <= n; ++j)
eu[i + j] = (eu[i + j] + ans[i] * pt1[j]) % MOD;
}
else {
int *ans = solve(k / 2);
for (int i = 1; i <= n; ++i)
for (int j = 1; j + i <= n; ++j)
eu[i + j] = (eu[i + j] + ans[i] * ans[j]) % MOD;
}
return eu;
}
int main()
{
int k;
int *ans;
fin >> n >> k;
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i % MOD;
for (int i = 1; i <= n; ++i) {
pt1[i] = fact[i];
for (int j = 1; j < i; ++j)
pt1[i] = (pt1[i] + MOD * MOD - pt1[j] * fact[i - j]) % MOD;
}
ans = solve(k);
fout << ans[n];
return 0;
}