Cod sursa(job #455385)

Utilizator S7012MYPetru Trimbitas S7012MY Data 13 mai 2010 17:46:19
Problema Nunta Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <cstdio>
#include <cstring>

int x[1000],y[1000],z[1000];

void add (int a[],int b[]) {
	int i,t=0;
	for(i=999; i>999-a[0]-1 || t; i--) {
		a[i]=(t+a[i]+b[i])%10;
		t=(a[i]+b[i]+t)/10;
	}
	a[0]=999-i-1;
}


int main()
{
	int n,i=0,ok=0;
	freopen("nunta.in","r",stdin);
	freopen("nunta.out","w",stdout);
	scanf("%d",&n);
	x[999]=0;
	y[999]=1;
	x[0]=y[0]=1;
	while(i++<n+1) {
		memcpy(z,x,sizeof(x));
		add(x,y);
		memcpy(y,z,sizeof(z));
	}
	//printf("%d",x[0]);
	for(i=999-x[0]+1; i<=999; i++) printf("%d",x[i]);
	return 0;
}