Cod sursa(job #732525)

Utilizator danalex97Dan H Alexandru danalex97 Data 10 aprilie 2012 16:54:53
Problema 12-Perm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>
using namespace std;

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

#define Mod 1048576
#define Modulo(x) ( x & (Mod-1) )
int N;

int next[] = { 0 , 2 , 3 , 4 , 1 };
int last[] = { 0 , 4 , 1 , 2 , 3 };
int A[]= { 0 , 1 , 2 , 6 , 12 };

int main()
{
	F>>N;
	
	int pl=4;
	for (int i=5;i<=N;++i)
		pl=next[pl] , A[pl]= Modulo ( Modulo( A[last[pl]] + A[last[last[last[pl]]]] ) + Modulo( 2*(i-2) ) ) ;
	
	if ( N>4 )
		G<<A[pl];
	else
		G<<A[N];
	
	F.close();
	G.close();
	return 0;
}