We need to keep our values as integer quantities, or else we inevitably lose precision and will fail on certain cases. This can get quite ugly in some problems, here we take another approach: Binary search the answer!
BINARY SEARCH THE ANSWERThis approach depends on a partitioning on two possible answers. Here, $hi$ represents the top segment (i.e. "yes, it is possible"), and $lo$ represents the bottom segment (i.e. "no, it is not possible"). It is good practice to avoid manually setting the inital values for $lo$ and $hi$, I know for a fact that if $lo = 0$ (i.e. 0 steps, which we already covered for in our special case check above), then it is a definite "no, it is not possible". Start $hi = 1$, and double it until our validation function returns true; this becomes our inital upper bound.
Another trick is don't try to nail down the exact case where you should stop, it is too error prone and unnecessary. Just give a little extra room, then increment/decrement $lo$/$hi$ after this loop to get your desired partition point; in this case, we want the smallest $x$, for which $f(x)$ returns true, so we'll walk the $lo$ up until true, and that's our answer.