Cod sursa(job #1279926)

Utilizator andrei.arnautuAndi Arnautu andrei.arnautu Data 1 decembrie 2014 03:04:56
Problema 12-Perm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#define Mod 1048575
using namespace std;
ifstream in("12perm.in");
ofstream out("12perm.out");
int N, a , b , c , d;

int main()
{
    in >> N;
    a = 1;
    b = 2;
    c = 6;
    d = 12;
    if( N == 1 )
        out << a;
    else if( N == 2 )
        out << b;
    else if( N == 3 )
        out << c;
    else if( N == 4 )
        out << d;
    else
    {
        a = 2;
        b = 6;
        c = 12;
        for(int i = 5 ; i <= N ; ++i )
        {
            d = c + a + 2 * (i - 2);
            d = d & Mod;
            a = b;
            b = c;
            c = d;
        }
        out << d;
    }
    return 0;
}