Cod sursa(job #147875)

Utilizator oumbraPaul Filimoon oumbra Data 3 martie 2008 17:57:29
Problema Koba Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <cstdio>

#define SIZE 10

char uc[SIZE][SIZE][SIZE];
char lastc[1000005];

long long sum = 0;

int main()
{		
	int a, b, c, i, n;

	for(i=0; i<1000; i++)
	{
		a = i%10;
		b = (i/10)%10;
		c = (i/100)%10;

		uc[a][b][c] = ((a*b)+c)%10;
	}

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

	scanf("%d%d%d%d", &n, &a, &b, &c);
	
	lastc[1] = a%10;
	lastc[2] = b%10;
	lastc[3] = c%10;

	sum += lastc[1] + lastc[2] + lastc[3];
	
	for(i=4; i <= n; i++)
	{
		lastc[i] = uc[lastc[i-3]][lastc[i-2]][lastc[i-1]];
		sum += lastc[i];
	}

	printf("%d\n", sum);

	return 0;
}