Cod sursa(job #2980447)

Utilizator gabriel10tm@gmail.comGabriel Marian [email protected] Data 16 februarie 2023 15:26:54
Problema 12-Perm Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.48 kb
#include <bits/stdc++.h>
using namespace std;
const int mod = 1048576;
#define cin fin
#define cout fout
ifstream fin("12perm.ins");
ofstream fout("12perm.out");
int main(){
    int n;
    cin >> n;
    int v[4] = {1,2,6,12};
    if(n <= 4){
        cout << v[n-1];
        return 0;
    }
    for(int i=5;i<=n;i++){
        int aux = v[2];
        v[2] = v[3];
        v[3] = v[3] + v[1] + 2*(i-2);
        v[3]%=mod;
        v[1] = aux;
    }
    cout << v[3];
}