I have given a log value Y
, i want to calculate the anti log of Y i.e
ans = (Math.pow(10,Y))%mod
where mod = 1e9+7
and the anti log of Y will always be integer i.e
Y is calculate as follow Y= log(a) a is very large integer of range 10^100000
So for given Y i need to calculate ans ? How to do that considering the mod operation.
My Approach
double D = Y -(int)Y
long Pow = (long)Y
for(int i=1;i<=Pow;i++) ans = (ans*10)%mod;
ans = (ans*Math.pow(10,D))%mod
But it's not correct can someone suggest be efficient approach here ? BigDecimal can be useful there ?
For Example:
Y = 16.222122660468525
Using the straight forward method and rounding off i.e Math.log(10,Y)
give me 1667718169966651
but using loops it's give me 16677181699666510
. I am not using mod now just explaining that there is an error.
Here Y
is small so direct method works and we can take mod easily. if Y is range of 10000 it will not work and overflow so we have to used mod.