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.
private static int longStrToModNum(string a, int m)
{
int offs = 18, len = a.Length, idx = len - ((len-1)%offs + 1);
long fctr = long.Parse($"1{new string('0', (len-1)%offs + 1)}") % m, res = long.Parse(a.Substring(idx)) % m;
long mod10s = long.Parse($"1{new string('0', offs)}") % m;
while (idx > 0)
{
idx -= offs;
res = (res + long.Parse(a.Substring(idx, offs)) % m * fctr % m) % m;
fctr = fctr * mod10s % m;
}
return (int)res;
}
public static int solve(string a, string b)
{
return (int)BigInteger.ModPow(longStrToModNum(a,1000000007), longStrToModNum(b,1000000006), 1000000007);
}
...not that speedy, but passing all tests
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Join us
Create a HackerRank account
Be part of a 26 million-strong community of developers
Please signup or login in order to view this challenge
Power of large numbers
You are viewing a single comment's thread. Return to all comments →
C# usin BigInteger (otherwise - russian peasant algorithm):
...not that speedy, but passing all tests