Cod sursa(job #2186747)

Utilizator YouDontNeedMyNameJurcut Paul YouDontNeedMyName Data 25 martie 2018 21:39:12
Problema 12-Perm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <fstream>
#define mod 1048576
using namespace std;
ifstream cin("12perm.in");
ofstream cout("12perm.out");
int v[6],n,k,nr;
int main()
{
    v[1]=1;
    v[2]=2;
    v[3]=6;
    v[4]=12;
    cin >> n;
    for(int i=5; i<=n; i++)
    {
        v[5]=(v[4]+v[2] + 2*(i-2))%mod;
        v[1]=v[2];
        v[2]=v[3];
        v[3]=v[4];
        v[4]=v[5];
    }
    if(n>=5)
        cout << v[5];
    else
        cout << v[n];
    return 0;
}