Cod sursa(job #193692)

Utilizator raduzerRadu Zernoveanu raduzer Data 6 iunie 2008 11:59:34
Problema 12-Perm Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.38 kb
#include <stdio.h>

int n;

int main()
{
	freopen("12perm.in","r",stdin);
	freopen("12perm.out","w",stdout);
	scanf("%d",&n);
	if (n<=2) { printf("%d",n); return 0;}
	if (n==3) { printf("6"); return 0; }
	if (n==4) { printf("12"); return 0; }
	int z=2,y=6,x=12,r=0;
	for (int i=5; i<=n; ++i)
	{
		r=(x+z+2*(i-2))%(1<<20);
		z=y; y=x; x=r;
	}
	printf("%d",r);
	return 0;
}