Cod sursa(job #2912445)

Utilizator MihatricepsMihalache Andrei Mihatriceps Data 8 iulie 2022 13:17:14
Problema Koba Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream f("koba.in");
ofstream g("koba.out");

int main()
{
    long long n, k, suma=0;
    int t1,t2,t3,t4;
    f>>n>>t1>>t2>>t3;
    if(n==1)
      g<<t1%10;
    if(n==2)
      g<<t2%10+t1%10;
    if(n==3)
      g<<t3%10+t2%10+t1%10;
    if(n>3)
    {
        t1%=10;
        t2%=10;
        t3%=10;
        suma=suma+t1+t2+t3;
        for(k=4;k<=n;k++)
        {
            t4=(t3%10)+(t2%10)*(t1%10);
            t4%=10;
            suma+=t4;
            t1=t2;
            t2=t3;
            t3=t4;
        }
        g<<suma;
    }
    return 0;
}