Educational Codeforces Round 66 (Rated for Div. 2) A. From Hero to Zero

链接:https://codeforces.com/contest/1175/problem/A

题意:

You are given an integer nn and an integer kk.

In one step you can do one of the following moves:

  • decrease nn by 11;
  • divide nn by kk if nn is divisible by kk.

For example, if n=27n=27 and k=3k=3 you can do the following steps: 2726252487621027→26→25→24→8→7→6→2→1→0.

You are asked to calculate the minimum number of steps to reach 00 from nn.

思路:

暴力,模拟。

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
LL n, m, k, t;

int main()
{
    cin >> t;
    while (t--)
    {
        cin >> n >> m;
        LL res = 0;
        while (n)
        {
            res += n%m;
            if (n >= m)
                res++;
            n = n/m;
//            cout << n << ' ' << res << endl;
        }
        cout << res << endl;
    }

    return 0;
}

  

posted @ 2019-06-06 12:03  YDDDD  阅读(183)  评论(0编辑  收藏  举报