I am an Undergraduate student and new to algorithmic Number theory. Recently I come to know about the method, when $b=2^k,k\in \mathbb{N}$, of computing $a^b \pmod{c}$ by computing $$((...(a\pmod{c})^2\pmod{c})...)^2 \pmod{c}$$
Now, for any natural number $b$ (usually big), not neceassaryly power of $2$, if we have a good algorithm to compute the best $n$ such that - $(b-n^k) \text{ is small with smallest } k\in \mathbb{N}$, in another way we need to compute $n$ which has $(b-n^k)+k,$ with $ n,k\in \mathbb{N}$ minimum. Then we can use:$$((...(a\pmod{c})^n\pmod{c})^n)...)^n \pmod{c}$$ to compute our desired number with minimum steps.
Note: Good algorithm for finding $n$ such that $(b-n^k)\le (b-p^l)$ for all $p\in \mathbb{N},l\in \mathbb{N}$ is also welcome. Also note that we are dealing with usually big $b$, with $90$ digits in decimal expansion(~$300$ binary digits) say, checking for such $n$ using for loop from $2$ to a number increasing each step by $1$ is not a good way.