Pagini recente » Borderou de evaluare (job #1011866) | Borderou de evaluare (job #436568) | Borderou de evaluare (job #1391969) | Borderou de evaluare (job #1989697) | Cod sursa (job #1967806)
#include <bits/stdc++.h>
using namespace std;
ifstream f("koba.in");
ofstream g("koba.out");
long long sum_here[1000][32] = {}, goes_to[1000][32], sum = 0, x, y, z, n, stare, i;
int main(){
for(i = 0; i < 1000; ++i)
goes_to[i][0] = (10*i + ((i/100) * (i/10) +i)%10)%1000,
sum_here[i][0] = i/100;
for(x = 1; x < 32; ++x)
for(i = 0; i < 1000; ++i)
goes_to[i][x] = goes_to[goes_to[i][x-1]][x-1],
sum_here[i][x] = sum_here[i][x-1] + sum_here[goes_to[i][x-1]][x-1];
f >> n >> x >> y >> z;
stare = 100 * (x%10) + 10 * (y%10) + z%10;
for(i = 0; n; ++i, n /= 2)
if(n%2)
sum += sum_here[stare][i],
stare = goes_to[stare][i];
g << sum << endl;
return 0; }