Cod sursa(job #2162012)

Utilizator maria15Maria Dinca maria15 Data 11 martie 2018 23:04:14
Problema Koba Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <fstream>

using namespace std;

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

int n, s, i;
short ant1, ant2, ant3, crt;

int main(){
    fin>>n>>ant3>>ant2>>ant1;
    ant3 %= 10;
    ant2 %= 10;
    ant1 %= 10;
    s = ant3%10 + ant2%10 + ant1%10;
    for(i=4;i<=n;i++){
        crt = (ant3 * ant2 + ant1)%10;
        s += crt;
        ant3 = ant2;
        ant2 = ant1;
        ant1 = crt;
    }
    fout<<s;
    return 0;
}