Pagini recente » Cod sursa (job #3152209) | Cod sursa (job #1070278) | Cod sursa (job #3183178) | Cod sursa (job #2296222) | Cod sursa (job #2134351)
#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;
}