Cod sursa(job #2443398)

Utilizator TheNextGenerationAyy LMAO TheNextGeneration Data 27 iulie 2019 19:09:31
Problema 12-Perm Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <bits/stdc++.h>

using namespace std;

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

const int MOD = (1 << 20);

int main()
{
    int n,a,b,c;
    in >> n;
    a = 2;
    b = 6;
    c = 12;
    for (int i = 5; i <= n; i++)
    {
        a = (c + a + ((i - 2) << 1)) % MOD;
        swap (a, c);
        swap (a, b);
    }

    if (n == 1) out << "1\n";
    else if (n == 2) out << a << '\n';
    else if (n == 3) out << b << '\n';
    else out << c << '\n';
    return 0;
}