Cod sursa(job #3152556)

Utilizator andrei1807Andrei andrei1807 Data 25 septembrie 2023 18:58:08
Problema Koba Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <iostream>
#include <fstream>

#define ll long long

using namespace std;

ifstream fin("koba.in");
ofstream fout("koba.out");

int main() {

    ll s = 0, n, t1, t2, t3, t;
    fin >> n >> t1 >> t2 >> t3;

    t1 = t1 % 10;
    t2 = t2 % 10;
    t3 = t3 % 10;

    s += t1;
    s += t2;
    s += t3;

    if (n == 1) {
        fout << t1;
        return 0;
    }
    if (n == 2) {
        fout << t1 + t2;
        return 0;
    }

    for (int i = 4; i <= n; i++) {
        t = t3 + t1 * t2;
        t = t % 10;

        t1 = t2;
        t2 = t3;
        t3 = t;

        s += t;
    }

    fout << s;

    return 0;
}