Cod sursa(job #2980621)

Utilizator gabriel.9619Gabriel Stefan Tita gabriel.9619 Data 16 februarie 2023 18:10:47
Problema Koba Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <fstream>
using namespace std;
ifstream fin("koba.in");
ofstream fout("koba.out");
int s[10001], f[10001];
int main()
{
    int n, t1, t2, t3, sumacrt, sol, ok, i, crt;
    fin>>n;
    fin>>t1>>t2>>t3;
    s[1]=t1%10;
    s[2]=s[1]+(t2%10);
    s[3]=s[2]+(t3%10);
    sumacrt=(t1%10)*100+(t2%10)*10+(t3%10);
    f[sumacrt]=3;
    ok=0;
    i=3;
    while(ok==0&&i<n)
    {
        i++;
        crt=t3+t2*t1;
        t1=t2%10;
        t2=t3%10;
        t3=crt%10;
        sumacrt=(t1%10)*100+(t2%10)*10+(t3%10);
        if(f[sumacrt]!=0)
        {
            ok=1;
        }
        else
        {
            f[sumacrt]=i;
        }
        s[i]=(s[i-1]+(t3%10));
    }
    if(ok==0)
    {
        fout<<s[n];
    }
    else
    {
        int poz, len, prod;
        sol=0;
        poz=f[sumacrt];
        len=i-poz;
        prod=(n-poz)/len;
        sol=s[poz]+(s[i]-s[poz])*prod;
        crt=(n-poz)%len;
        sol+=(s[poz+crt]-s[poz]);
        fout<<sol;
    }
}