链接: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: 27→26→25→24→8→7→6→2→1→027→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;
}

  

Educational Codeforces Round 66 (Rated for Div. 2) A. From Hero to Zero的更多相关文章

  1. Educational Codeforces Round 66 (Rated for Div. 2) B. Catch Overflow!

    链接:https://codeforces.com/contest/1175/problem/B 题意: You are given a function ff written in some bas ...

  2. Educational Codeforces Round 66 (Rated for Div. 2) A

    A. From Hero to Zero 题目链接:http://codeforces.com/contest/1175/problem/A 题目 ou are given an integer n ...

  3. Educational Codeforces Round 66 (Rated for Div. 2)

    A.直接模拟. #include<cstdio> #include<cstring> #include<iostream> #include<algorith ...

  4. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  5. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  6. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  7. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  8. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  9. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

随机推荐

  1. BZOJ 1579 [Usaco2009 Feb]Revamping Trails 道路升级:dijkstra 分层图【将k条边改为0】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1579 题意: 给你一个无向图,n个点,m条边,每条边有边权w[i]. 你可以将其中的k(k ...

  2. 四连测Day4

    四连爆炸 卡我常数 好像被AluminumGod拉到了创客...哇我这个天天爆炸的水平可能会被其他三位dalao吊起来打 orz Edmond-Karp_XiongGod orz Deidara_Wa ...

  3. 【LeetCode】091. Decode Ways

    题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: ' ...

  4. sql基础内容2

    -- day16课程内容 --CREATE DATABASE day16;USE day16; -- *************一.数据约束********************------ 1.1 ...

  5. 【转】Pro Android学习笔记(一):Android 平台 2013.6.4

    本系列是阅读<Pro Android4>的读书笔记,也包括网络阅读资料的整理,以及个人心得. 由于智能手机引入AP(应用处理器),Android在某种意义上是个人计算机,具有桌面计算机的完 ...

  6. AI-Info-Micron-Insight:Micron 美光的技术帮助 CERN 解开宇宙奥秘

    ylbtech-AI-Info-Micron-Insight:Micron 美光的技术帮助 CERN 解开宇宙奥秘 1.返回顶部 1. Micron 美光的技术帮助 CERN 解开宇宙奥秘 大约 14 ...

  7. shell中利用ftp 上传文件夹功能

    我们知道ftp 只能用来上传或者下载文件,一次单个或者多个,怎么实现将文件夹的上传和下载呢? 可以利用先在remote ip上建立一个相同的文件夹目录,然后将文件放到各自的目录中去 1.循环遍历出要上 ...

  8. java性能调优的11个建议

    1.在必要之前,先不要优化 2.使用分析器来找到真正的瓶颈 3 .为整个应用程序创建性能测试套件 4.首先解决最大的瓶颈问题 5.使用StringBuilder以编程方式连接字符串       Str ...

  9. 在Windows环境中学习Linux

    如何在Windows环境下学习Linux?方法如下: 方法一: 下载Cygwin,Cygwin是一个在windows平台上运行的类UNIX模拟环境,网上有很多安装教程,这里不多说. 方法二: 下载一个 ...

  10. Arduino 元件

    http://www.rs-online.com/designspark/electronics/