LeetCode 483: Smallest Good Base I'm posting my code for a LeetCode problem. If you'd like to review, please do so. Thank you for your time!
Problem

For an integer n, we call k&gt;=2 a good base of n, if all digits of n
base k are 1.
Now given a string representing n, you should return the smallest good
base of n in string format.
Example 1:

Input: &quot;13&quot;
Output: &quot;3&quot;
Explanation: 13 base 3 is 111.

Example 2:

Input: &quot;4681&quot;
Output: &quot;8&quot;
Explanation: 4681 base 8 is 11111.

Example 3:

Input: &quot;1000000000000000000&quot;
Output: &quot;999999999999999999&quot;
Explanation: 1000000000000000000 base 999999999999999999 is 11.

Note:

The range of n is [3, 10^18].
The string representing n is always valid and will not have leading zeros.


Inputs
&quot;1000000000000000000&quot;
&quot;999999999999999999&quot;
&quot;141038407950127511&quot;
&quot;836507047502348570&quot;
&quot;123489798271512411&quot;
&quot;995437985793784539&quot;
&quot;4681&quot;
&quot;4800&quot;
&quot;48000&quot;
&quot;480000&quot;
&quot;5120000&quot;
&quot;51200000&quot;


Outputs

&quot;999999999999999999&quot;
&quot;999999999999999998&quot;
&quot;141038407950127510&quot;
&quot;836507047502348569&quot;
&quot;123489798271512410&quot;
&quot;995437985793784538&quot;
&quot;8&quot;
&quot;4799&quot;
&quot;47999&quot;
&quot;479999&quot;
&quot;5119999&quot;
&quot;51199999&quot;

Code
#include &lt;cstdint&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;

struct Solution {
    std::string smallestGoodBase(const std::string n) {
        std::uint_fast64_t num = (std::uint_fast64_t) std::stoull(n);
        std::uint_fast64_t x = 1;

        for (int bit = 62; bit &gt; 0; --bit) {
            if ((x &lt;&lt; bit) &lt; num) {
                std::uint_fast64_t curr = binarySearch(num, bit);

                if (curr) {
                    return std::to_string(curr);
                }
            }
        }

        return std::to_string(num - 1);
    }

private:

    static std::uint_fast64_t binarySearch(
        const std::uint_fast64_t num,
        const
        std::uint_fast8_t bit
    ) {
        const long double dnum = (long double) num;
        std::uint_fast64_t lo = 1;
        std::uint_fast64_t hi = (std::uint_fast64_t) (std::pow(dnum, 1.0 / bit) + 1);

        while (lo &lt; hi) {
            std::uint_fast64_t mid = lo + ((hi - lo) &gt;&gt; 1);
            std::uint_fast64_t sum = 1;
            std::uint_fast64_t curr = 1;

            for (std::uint_fast8_t iter = 1; iter &lt;= bit; ++iter) {
                curr *= mid;
                sum += curr;
            }

            if (sum == num) {
                return mid;

            } else if (sum &gt; num) {
                hi = mid;

            } else {
                lo = mid + 1;
            }
        }

        return 0;
    }
};


References

Problem

Discuss

Solution
Don't use std::uint_fast*_t
The performance gain of these types is minimal. If you really need to squeeze out the last bits of performance, it might help, but only if:

These types are actually different from the regular std::uint*_t
Implicit casts and integer promotions don't change the actual type used

The drawback is that the type names get very verbose. Also, can a std::uint_fast64_t actually hold an unsigned long long? The latter might very well be 128 bits long.
I suggest you stick with (unsigned) int when dealing with numbers that don't grow large (for example, for counting bits), size_t when you need to support arbitratily large counts, sizes and array indices, and other types as appropriate, such as unsigned long long to store the results of std::stoull().
Also use a using declaration to declare the type used to store the numbers in one place, so if you ever decide to change it, you don't have to search and replace all over the code. You can combine it with decltype() to get the type returned by an arbitrary function, like so:
class Solution {
    using value_type = decltype(std::stoull(&quot;&quot;));
    ...
};

Avoid unnecessary one-use temporaries
There are several cases where you define a temporary variable that is only used once, and which could be avoided. The first is x, which is only used to create a constant 1 of the right type. You can do that instead like so:
if ((value_type{1} &lt;&lt; bit) &lt; num) {
    ...
}

The second one will still technically create a temporary, but we can use C++17's if with an init statement:
if (auto curr = binarySearch(num, bit); curr) {
    return curr;
}

When passing an integer type to std::pow(), it will convert it to double for you, so you don't have to explcitly create a temporary constant dnum, and can just write:
value_type hi = std::pow(num, 1.0 / bit) + 1;

Note that you also don't need to explicitly cast it back to an integer here.