Need help with floating point format

I am trying to solve problem. The solution is simple. But storing number in long long is not enough. So I studied the approach of the editorial. It takes logarithm to solve it. I have two doubts.

  1. The logarithmic part is not giving correct answer as floating point operations are not accurate. For second test case, the answer is 105, I am getting 104. Here’s my code without modulo operation.
    What can I do to fix it?

  2. How do I perform the modulo operation on a exponentiation where power is a floating point number? I know modular exponentiation but there base and exponents are integers. What can be done for floating point?

take log of all values and store a array say A[]

and trace all path compare according to question what you need and mark your optimal path

and after that just move along that path ans=(ans*curr_node_value_of_optimal_path_original)%MOD;

print ans;
Take A look at my solution


1 Like