It is not very clear what you are trying to optimise.
What you need to do is calculate or guess a value of a which is too small and one that is too big. Having got those, try a value between them. If this is too big then try a value between the lower limit and the midpoint. If it is too small then try a value which is between between the midpoint and the upper limit. Now, you have restricted the range of possible answers; try the midpoint of those and repeat.
For example, let's try to find the square root of $2$ this way.
We can guess and then check that $1$ is too small.
We can guess and then check that $2$ is too big.
Now, we try $1.5$. $1.5^2 = 2.25$ so that is too big.
So, we know that the answer is between $1$ and $1.5$. So, we try $1.25$ next.
If you cannot guess an upper limit then one strategy is to make any guess and keep doubling it until it is too big. Let's suppose that we are trying to find the square root of $10$ but we have no idea what it is.
We start with $1$ and we find that it is too small.
So, we double it and try $2$ which is also too small.
So, we double it and try $4$ which is too big.
We now know that the answer is between $2$ and $4$ so we can return to the previous algorithm and try $3$. We find that $3$ is too small so we try $3.5$ etc.