Cod sursa(job #754379)

Utilizator Stefex09Stefan Teodorescu Stefex09 Data 1 iunie 2012 21:29:31
Problema Nunta Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include<cstdio>

using namespace std;

/*ifstream in("nunta.in");
ofstream out("nunta.out");*/

int a[210], b[210], c[210];

int main()
{
	freopen("nunta.in", "r", stdin);
	freopen("nunta.out", "w", stdout);
	
	int N, i, j, t = 0;
	
	//in >> N;
	scanf("%d", &N);
	
	if(N <= 3){
		//out << N;
		printf("%d", N);
		return 0;
	}
	
	a[0] = b[0] = c[0] = 1;
	a[1] = 1; b[1] = c[1] = 2;
	
	for(i = 3; i <= N; ++i, t = 0){
		for(j = 1; j <= c[0] || j <= a[0] || t; ++j, t /= 10)
			c[j] = (t += c[j] + a[j]) % 10;
		
		c[0] = j - 1;
		
		for(j = 0; j <= b[0]; ++j)
			a[j] = b[j];
		
		for(j = 0; j <= c[0]; ++j)
			b[j] = c[j];
	}
	
	for(i = c[0]; i; --i)
		//out << c[i];
		printf("%d", c[i]);
	
	return 0;
}