Cod sursa(job #122619)

Utilizator RobytzzaIonescu Robert Marius Robytzza Data 13 ianuarie 2008 09:58:15
Problema 12-Perm Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb
#include <fstream.h>
//using namespace std;
int main(){
ifstream fin("12perm.in");
ofstream fout("12perm.out");
long N;
long b=2,c=6,d=12,Max=1048576;
fin>>N;
for (int i=5;i<=N;i++)
{
    long aux=d;
    d=(d+b+2*(i-2))%Max;
    b=c;
    c=aux %Max;
}
if (N==4)
   fout<<12;
   else
if (N==3)
   fout<<6;
else
if (N==2)
   fout<<2;
else
if (N==1)
   fout<<1;
else
fout<<d % Max;
fout<<"\n";
fin.close();
fout.close();
return 0;
}