当前位置: 首页 > news >正文

Codeforces Round 976 (Div. 2) A. Find Minimum Operations

这个问题实际上是K进制取位和:
举例:2进制 n=110100 使用几次2的x次幂可以将n置0,ans=3
10进制 n=9924 使用几次10的x次幂可以将n置0,ans=9+9+2+4
k进制也相同 ,代码如下:
`#include <bits/stdc++.h>
using namespace std;
using ll = long long; // constexpr 0LL
using ull = unsigned long long; // constexpr 0ULL
using ui = unsigned int; // constexpr U
using ld = long double; // constexpr 0.0L
using pii = pair<int, int>;
using pll = pair<ll, ll>;

define endl '\n'

define inf 0x3f3f3f3f

define xx first

define yy second

define lowbit(x) x & -x

const int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
const ll linf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
void solved()
{
ll n, k;
cin >> n >> k;
if (k == 1||k>n)
{
cout << n << endl;
return;
}
int ans=0;
while(n>0){
ans+=n%k;
n /= k;
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
cin >> T;
while (T--)
{
solved();
}
return 0;
}`

http://www.gsyq.cn/news/28790.html

相关文章:

  • 20251021 NOIP模拟赛
  • RocketMQ+Spring Boot的简单实现及其深入分析
  • XSD 文档(XML Schema Definition)简介
  • LLM 场景下的强化学习技术扫盲
  • vmware虚拟机下载安装教程(付安装包)详细图文下载安装教程
  • deepin 25 虚拟机安装vgpu客户机驱动
  • CF2153D
  • 英语_阅读_inspiration for artists_待读
  • Node.js JSON import attributes All In One
  • DeepSeek的“认知提纯”能力解析
  • Plya 定理学习笔记 | ABC428G 题解
  • 告别繁琐排版!揭秘2025年公众号推文排版top1神器
  • leetcode1. 两数之和、15. 三数之和、18. 四数之和
  • vue3+elementPlus el-date-picker 自定义禁用状态hook 建立结束时间不能小于开始时间
  • 【做题记录】贪心--提高组
  • 【为美好CTF献上祝福】 New Star 2025 逆向笔记
  • XXL-JOB(5)
  • Ramanujan Master Theorem
  • 【周记】2025.10.13~2025.10.19
  • C++案例 自定义数组
  • 20251023周四日记
  • ord() 函数
  • Redis中的分布式锁之SETNX底层实现
  • 2025家纺摄影公司推荐,南通鼎尚摄影专注产品视觉呈现
  • 求函数
  • Python---简易编程解决工作问题
  • MPK(Mirage Persistent Kernel)源码笔记(1)--- 基础原理
  • 背包dp(1)
  • 比赛题解 总结
  • 1019:浮点数向零舍入(分正负取整)