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.

43 lines
895 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include <bits/stdc++.h>
using namespace std;
long long n, ans;
int k, len;
long long d[1000000];
int main() {
cin >> n >> k;
d[0] = 0;
len = 1;
ans = 0;
for (long long i = 0; i < n; ++i) {
++d[0]; //每次个位 +1
//进位处理到倒数第二高位
for (int j = 0; j + 1 < len; ++j) {
if (d[j] == k) { //如果本位到达了k进制的k这个数本位置0向前进1
d[j] = 0;
d[j + 1] += 1;
++ans; //记录进位次数
}
}
//最高位单独处理 涉及到len的调整
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 << len << endl;
//输出进位次数
// cout << ans << endl;
return 0;
}