Cod sursa(job #1395951)

Utilizator mircea.dobreanuMircea Dobreanu mircea.dobreanu Data 21 martie 2015 20:40:15
Problema 12-Perm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.41 kb
#include <fstream>
using namespace std;

ifstream fin("12perm.in");
ofstream fout("12perm.out");
const int kMax = 15000000;
const int kMod = (1 << 20);
int dp[kMax];


int main()
{
    int n;    fin >> n;

    dp[1] = 1;
    dp[2] = 2;
    dp[3] = 6;
    dp[4] = 12;
	for (int i = 5; i <= n; ++i)
		dp[i] = (dp[i - 1] + dp[i - 3] + 2 * (i - 2)) & (kMod - 1);

	fout << dp[n] << '\n';
	return 0;
}