You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

2 years ago
/*
nkans,len
https://blog.csdn.net/qq_23109971/article/details/111396755
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int n, ans, k, len = 1; //最少是1位长度
int d[N];
int main() {
cin >> n >> k; // n要转换的10进制数k:k进制
//从0开始枚举每小于n的数字一个个叠加上去
for (int i = 0; i < n; i++) {
++d[0]; //将叠加上来的1先放到个位上
for (int j = 0; j < len - 1; j++) //看看会不会对现在的每一个位置造成进位?
if (d[j] == k) {
d[j] = 0;
d[j + 1] += 1;
++ans; //记录进位次数
}
//最高位单独处理
if (d[len - 1] == k) {
d[len - 1] = 0;
d[len] = 1;
++len;
++ans;
}
//输出k进制的表示法
// for (int i = len - 1; i >= 0; i--) cout << d[i];
// cout << endl;
}
//输出进位次数
// cout << ans << endl;
cout << len << endl;
//输出k进制的表示法
// for (int i = len - 1; i >= 0; i--) cout << d[i];
// cout << endl;
return 0;
}