how to write power functions in case of high powers (in the range of 10^9).
pow function in c++ can’t handle this (as result can’t be stored)
USE MODULAR AIRTHEMATIC PROPERTIES TO DO THIS
1 Like
And Binary Exponentiation along with it shall also help.
1 Like
Consider a recursive approach.
when n is even
pow(x,n)=pow(x,n/2)*pow(x,n/2) // in case of n being even
when n is odd
pow(x,n)=pow(x,n/2)*pow(x,n/2)*x; // in case of n being odd
also use modular arithmetic.
2 Likes