Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- typedef unsigned long long ull;
- string smallestGoodBase(string n) {
- ull N = stoll(n), maxM = log2(N);
- for(int m=maxM; m>=2; m--){
- ull k = ull(pow(N, 1.0/m));
- ull prod = 1, sum = 1;
- for(int j=1; j<=m; j++){
- prod *= k;
- sum += prod;
- }
- if(sum == N)
- return to_string(k);
- }
- return to_string(N-1);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement