how to find the least number of operations to compute x^n
See this: http://en.wikipedia.org/wiki/Addition-chain_exponentiation
There is no efficient algorithm that will get you the minimum number of steps, and dynamic programming does not work.
I am guessing that n
is small enough to allow a brute force solution to pass, although it might need to be optimized. Do you know how to brute force it?