Cod sursa(job #17364)

Utilizator peanutzAndrei Homorodean peanutz Data 15 februarie 2007 19:25:47
Problema Patrate2 Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <stdio.h>

int i, t, j, n;
int a[1010][100];
int fact[30000];

int c[30000];

int main()
{
int np;
freopen("patrate2.in", "r", stdin);
freopen("patrate2.out", "w", stdout);


scanf("%d\n", &n);

np = n*n+1;


a[1][0] = a[1][1] = 1;

for(i = 2; i <= np; ++i)
	{
		for(j = 1, t = 0; j <= a[i-1][0] || t; ++j, t /= 10)
			a[i][j] = (t += a[i-1][j]*2) % 10;

		a[i][0] = j-1;
	}


/*for(i = 0; i <= 101; ++i)
	{
		for(j = a[i][0]; j; --j)
			printf("%d", a[i][j]);

		printf(",\n");
	}
*/

fact[0] = fact[1] = 1;



for(i = 1; i <= n; ++i)
	{
		for(j = 1, t = 0; j <= fact[0]  ||  t; ++j, t /= 10)
			fact[j] = (t += fact[j] * i) % 10;
		fact[0] = j-1;
	}



for(i = 1; i <= fact[0]; ++i)
	{
		for(j = 1, t = 0; j <= a[np][0] || t; ++j, t /= 10)
			c[i+j-1] = (t += a[np][j]*fact[i]) % 10;

		if(i+j-2 > c[0])
			c[0] = i+j-2;
	}



for(j = c[0]; j; --j)
	printf("%d", c[j]);



fclose(stdin);
fclose(stdout);

return 0;
}