Cod sursa(job #419125)

Utilizator andreirulzzzUPB-Hulea-Ionescu-Roman andreirulzzz Data 16 martie 2010 22:56:12
Problema Koba Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <cstdio>
#define FOR(i,a,b) for(i=a;i<=b;i++)
using namespace std;

int t1,t2,t3,n,s,t4,k,s1;

int main()
{
	freopen("koba.in","r",stdin);freopen("koba.out","w",stdout);scanf("%d%d%d%d",&n,&t1,&t2,&t3);
	if (n>=1) s=t1%10;
	if (n>=2) s+=t2%10;
	if (n>=3) s+=t3%10;
	t1%=10;t2%=10;t3%=10;
	n-=3;
	k=997;
	while (k--)
	{
		t4=(t3+t2*t1)%10;
		t1=t2;t2=t3;t3=t4;
		s+=t4;
	}
	t4=t3;t3=t2;t2=t1;
	s1=s;
	while (n-1000>0)
	{
		n-=1000;
		s+=s1;
	}
	while (n<0)
	{
		t1=(t4-t3/t2)%10;
		t4=t3;
		t3=t2;
		t2=t1;
		s-=t1;++n;
	}
	printf("%d\n",s);
	return 0;
}