For a math routine I need a lookup table of exponent "n" of 251 for all integers 0 < n < 65536. Furthermore, the result are to be trimmed to modulo 216, i.e., stored in a 16-bit variable. In other words,
uint16_t result[65536];
void calculate_exponent_lookup_table(void)
{
for (uint16_t i = 0 ; i < 65536 ; i++)
result[i] = pow(251, i) % 65536;
}
But due to resource limitations, I don't have space to separately calculate and store the "result"
array statically, nor the computation power to calculate the higher order exponents by repeated multiplication in the given time duration, at run-time.
So, I came across this link about Binary Exponentiation.
Using the above algorithm, I need to pre-calculate and store 16 exponents of 251 i.e 2511 to 25116. I just need to do 16 multiplications, i.e. log 65536, at maximum to obtain any exponent, during runtime, which is doable.
But since the results are going to be stored modulo 216, can I still optimize this and save some computation?