Cod sursa(job #984525)

Utilizator AlexandruValeanuAlexandru Valeanu AlexandruValeanu Data 14 august 2013 18:09:02
Problema 12-Perm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>

using namespace std;

const int mask = ( 1 << 20 ) - 1;

int N;
int T[6];

/// T[1] = 1, T[2] = 2, T[3] = 6, T[4] = 12;
/// T[i] = T[i - 1] + T[i - 3] + 2 * (i - 2)

int main()
{
    ifstream f("12perm.in");
    ofstream g("12perm.out");

    f >> N;

    T[1] = 1, T[2] = 2, T[3] = 6, T[4] = 12;

    if ( N < 5 )
        g << T[N] << "\n";
    else
    {
        for ( int i = 5; i <= N; ++i )
        {
            T[5] = ( T[4] + T[2] + 2 * ( i - 2 ) ) & mask;

            T[2] = T[3];
            T[3] = T[4];
            T[4] = T[5];
        }

        g << T[5] << "\n";
    }

    f.close();
    g.close();

    return 0;
}