Pagini recente » Cod sursa (job #70255) | Cod sursa (job #348421) | Cod sursa (job #3238585) | Cod sursa (job #2044093) | Cod sursa (job #2134349)
#include <bits/stdc++.h>
using namespace std;
const int MOD = (1 << 20) - 1;
const int QUEUEMOD = 3;
int dp[QUEUEMOD + 1] = {1, 2, 6, 12};
int main()
{
int n;
ifstream fin("12perm.in");
fin >> n;
fin.close();
for (int i = 4, ind = 0; i < n; ++i, ind = ((ind + 1) & QUEUEMOD))
dp[ind] = ((dp[(ind + 1) & QUEUEMOD] + dp[(ind + 3) & QUEUEMOD] + 2 * i - 2) % MOD);
ofstream fout("12perm.out");
fout << dp[(n - 1) & QUEUEMOD];
fout.close();
return 0;
}