Cod sursa(job #193690)

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

int n,i,x,y,z,r;

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; }
	z=2; y=6; x=12;
	for (i=5; i<=n; ++i)
	{
		r=(x+z+2*(i-2))%(1<<20);
		z=y; y=x; x=r;
	}
	printf("%d",r);
	return 0;
}