Cod sursa(job #1253611)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 1 noiembrie 2014 15:40:36
Problema Koba Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<fstream>
using namespace std;
int n, a, b, c, x, m, sum, t1, t2, t3, i, d, s, j;
int v[1000], f[1000];
ifstream fin("koba.in");
ofstream fout("koba.out");
int main(){
	fin>> n >> t1 >> t2 >> t3;
	a = t1 % 10;
	b = t2 % 10;
	c = t3 % 10;
	x = a * 100 + b * 10 + c;
	v[x] = 1;
	f[1] = x;
	d = (a * b + c) % 10;
	x = b * 100 + c * 10 + d;
	v[x] = 2;
	s = a + b + c + d;
	f[2] = x;
	for(i = 3; i <= n; i++){
		a = b;
		b = c;
		c = d;
		d = (a * b + c) % 10;
		s += d;
		x = b * 100 + c * 10 + d;
		f[i] = x;
		if(v[x] != 0){
			break;
		}
		else{
			v[x] = i;
		}
	}
	s-= (x / 100 + x / 10 % 10 + x % 10);
	m = i - v[x] + 1;
	for(j = v[x] - 2; j <= i - 2; j++){
		sum += f[j] % 10; 
	}
	n -= (i - 2);
	s += (n / m) * sum;
	for(j = v[x] - 2; j < n % m; j++){
		s += f[j] % 10;
	}
	fout<< s;
	return 0;
}