class Solution {
public:
string smallestGoodBase(string n) {
long long x = stol(n);
for(int i = 2; i <= 60; i++){
long long k = pow(x,1.0/(1.0*i));
if(k == 1) continue;
long long sum = 0;
long long t = 0;
for(int j = 0; j <= i; j++){
if(!j) t = 1;
else t *= k;
sum += t;
}
if(sum == x) return to_string(k);
}
return to_string(x-1);
}
};
Leetcode 483 最小好进制
最新推荐文章于 2024-11-16 12:43:59 发布