Cod sursa(job #1253706)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 1 noiembrie 2014 18:04:15
Problema Koba Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 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;
    if(x != f[1]){
        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 < v[x] + m - 2; j++){
        sum += f[j] % 10;
    }
    n -= i;
    s += (n / m) * sum;
    for(j = v[x] - 2; j < n % m + v[x] - 4; j++){
        s += f[j] % 10;
    }
    fout<< s;
    return 0;
}