Cod sursa(job #2098218)

Utilizator tziplea_stefanTiplea Stefan tziplea_stefan Data 2 ianuarie 2018 16:09:32
Problema 12-Perm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>
#include <algorithm>
#define VAL 105
#define MOD (1 << 20)

using namespace std;

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

int N, i, j;
int ANS, a, b, c;

int main()
{
    fin >> N;
    if (N==1)
      fout << 1;
    if (N==2)
      fout << 2;
    if (N==3)
      fout << 6;
    if (N==4)
      fout << 12;
    if (N>5)
    {
        a=12;
        b=6;
        c=2;
        for (i=5; i<=N; i++)
        {
            ANS=a+c+2*i-4;
            ANS%=MOD;
            c=b;
            b=a;
            a=ANS;
        }
        fout << ANS << '\n';
    }
    fin.close();
    fout.close();
    return 0;
}