i am unable to understand fast power function, its code please help
I am unable to understand fast power function
@agarwalarjit.agarwal in the code we are following a simple rule, if of type 2n(even), then if we find answer for n, we will get answer for 2n (a^2n = a^n * a^n).
if power is of type 2n+1(odd), the we find answer for n and the calculate ans for 2n and then for 2n+1, (a^(2n+1)= a * a^n * a^n ). (if a number is odd it must have last bit 1, cause if last bit is 0, then it will become divisible by 2, so for every odd number odd&1 is true)
And we have a base case for n==0.
If this resolves your doubt mark it as resolved.