Cod sursa(job #204179)

Utilizator AndreiDDiaconeasa Andrei AndreiD Data 22 august 2008 12:58:54
Problema Patrate2 Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <stdio.h>

#define BAZA 1000000000
typedef int hugeNR[8192];

int N;
hugeNR Res,Res1,rez;

void init(hugeNR H, unsigned long X)
{
  H[0] = 0;   
  while (X) {   
      ++H[0];   
      H[H[0]] = X % BAZA;
      X /= BAZA;
  }   
}


void inm(hugeNR a)
{
	int i, t = 0;

	for (i = 1; i <= a[0] || t; ++i, t /= BAZA)
		a[i] = (t += a[i]+a[i]) % BAZA;
	a[0] = i-1;
}

void inm1(hugeNR a ,hugeNR b,hugeNR c)
{
	int i, t = 0;

	for (i = 1; i <= a[0] || i<=b[0] || t; ++i, t /= BAZA)
		c[i] = (t += a[i]*b[i]) % BAZA;
	c[0] = i-1;
}

int main(void)
{
	int i;

	freopen("patrate2.in", "r", stdin);
	freopen("patrate2.out", "w", stdout);

	scanf("%d", &N);
	init(rez,N);
	Res[0] = Res[1] = 1;
	for (i = 1; i <= N*N; ++i)
		inm(Res);	

		inm1(Res,rez,Res1);
	printf("%d", Res1[Res1[0]]);
	for (i = Res1[0]-1; i; --i)
		printf("%09d", Res1[i]);
	printf("\n");

	return 0;
}