Cod sursa(job #764375)

Utilizator informatician28Andrei Dinu informatician28 Data 4 iulie 2012 22:28:53
Problema 12-Perm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <fstream>
#define DIM 15000001

using namespace std;

ifstream in("12perm.in");
ofstream out("12perm.out");

int N, best[DIM], mod = (1<<20)-1;

int main()
{
    best[1] = 1;
    best[2] = 2;
    best[3] = 6;
    best[4] = 12;
    in >> N;
    for (int i = 5; i <= N; i++)
    {
       best[i] = best[i-1] + best[i-3] + 2*(i-2);
       best[i] &= mod;
    }
    out << best[N];
    return 0;
}