Cod sursa(job #160358)

Utilizator sraduvictorSarmasag Radu Victor sraduvictor Data 15 martie 2008 11:17:22
Problema Koba Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <cstdio>
#include <cstdlib>

int main( int argc, char *argv[] )
{
	int n, t1, t2, t3;
	FILE *fin = fopen( "koba.in", "r" );
	fscanf( fin, "%d %d %d %d", &n, &t1, &t2, &t3 );
	fclose( fin );
	
	t1 = t1 % 10;
	t2 = t2 % 10;
	t3 = t3 % 10;
	long long suma = t1 + t2 + t3;
	
	for ( int i = 3; i < n; i++ )
	{
		int temp = ( t3 + t2*t1 ) % 10;
		t1 = t2;
		t2 = t3;
		t3 = temp;
		suma += t3;
	}
	
	FILE *fout = fopen( "koba.out", "w" );
	fprintf( fout, "%lld\n", suma );
	fclose( fout );
	
	return 0;
}