Cod sursa(job #333790)

Utilizator iulia609fara nume iulia609 Data 23 iulie 2009 21:11:15
Problema Koba Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<stdio.h>
#define dim 100000
using namespace std;

int t[dim];

int main()
{ 
  long long n,i,s,j,poz;

	FILE *f = fopen("koba.in", "r");
	FILE *g = fopen("koba.out", "w");
	
	n = 0;
	fscanf(f, "%lld", &n);
	fscanf(f, "%d%d%d",&t[1],&t[2], &t[3]);
	
	t[1] = t[1]%10;
	t[2] = t[2]%10;
	t[3] = t[3]%10;
	s = t[1]+t[2]+t[3];
	//s = 0;
	for(i = 4; i <= n; i++)
		{
			t[i] = (t[i-1] + (t[i-2]*t[i-3])%10)%10;
			s += t[i];
			if(t[i-2]==t[1] && t[i-1]==t[2] && t[i] == t[3])
				{
					poz = i-2;
					//s -= t[i]+t[i-1]+t[i-2];
					s = s*(n/poz);
					for(j = 1; j <= n%poz; j++)
						s += t[j];
					break;
				}
		}
	
	fprintf(g, "%lld\n", s);
	
	fclose(f);
	fclose(g);
	return 0;
}