Cod sursa(job #2766418)

Utilizator Bogdan.paun50Mandresi Bogdan Bogdan.paun50 Data 1 august 2021 14:27:50
Problema Koba Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <iostream>
#include <fstream>

using namespace std;

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

long long s[1005][32], nxt[1005][32];
int main()
{
    for(int i = 0; i < 1000; i++)
    {
        nxt[i][0] = (10*i+((i/100)*(i/10)+i)%10) % 1000;
        s[i][0] = i / 100;
    }

    for(int x = 1; x < 32; x++)
        for(int i = 0; i < 1000; i++)
        {
            nxt[i][x] = nxt[nxt[i][x-1]][x-1];
            s[i][x] = s[i][x-1]+s[nxt[i][x-1]][x-1];
        }
    int n;
    int x, y, z;
    fin >> n >> x >> y >> z;
    long long sum = 0;
    int st = 100*(x%10)+10*(y%10)+z%10;
    for(int i = 0; n; i++, n>>=1)
        if(n&1)
        {
            sum += s[st][i];
            st = nxt[st][i];
        }
    fout << sum << "\n";
    return 0;
}