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
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Permutations
You are viewing a single comment's thread. Return to all comments →
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