We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

I've been trying to use fast exponential method to calculate:
(Dr)^(p-2). using recursion.
but im getting run time error: Terminated due to time out.
this is my function to the fast method:

static int fastPowerMethod(long num, long power, long mod) {

its works now - no "run time error: Terminated due to time out" occurs.
but it doesnt work with the prime number 10^9 + 7. i tried some other small prime numbers (like 5,7,23,101...) and it worked for "Test 1", but not with 10^9+7... please help

## Sherlock and Permutations

You are viewing a single comment's thread. Return to all comments →

So, in our next step we need the help of

higher powers, or we need to calculateab %m.Suppose we need to calculate

2100 % 11.Now popping whole stack,

thank you very much,it works!

Sir please check my program , I am getting wrong answer . I have implemented your concept https://www.hackerrank.com/challenges/sherlock-and-permutations/submissions/code/18386949

I've been trying to use fast exponential method to calculate: (Dr)^(p-2). using recursion. but im getting run time error: Terminated due to time out. this is my function to the fast method:

can you tell me if i did something wrong?

P.S the rest of the code works fine

*** edit ***

its works now - no "run time error: Terminated due to time out" occurs. but it doesnt work with the prime number 10^9 + 7. i tried some other small prime numbers (like 5,7,23,101...) and it worked for "Test 1", but not with 10^9+7... please help