Cod sursa(job #417554)

Utilizator pykhNeagoe Alexandru pykh Data 14 martie 2010 15:38:34
Problema 12-Perm Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include<stdio.h>
const char in[]="12perm.in", out[]="12perm.out";
const int mod = 1048576;
int sol, n , j , last, aux;
int t[]={0, 1, 2, 6, 12};
int main()
	{
	freopen(in,"r",stdin);
	freopen(out,"w",stdout);
		scanf("%d", &n);
		for(j = 5 ; j <= n ; ++j)
		{
			aux = t[4];
			t[4] = t[4] + t[2] + 2 * ( j - 2 );
			if(t[4] > mod) t[4] -= mod;
			t[2] = t[3]; t[3] = aux;
		}
		if(n <= 4)printf("%d\n", t[n]);
		else printf("%d\n", t[4]);
		return 0;
}