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 gcdExtended(int a, int b, out int x, out int y)
{
if (a == 0)
{
x = 0; y = 1;
return b;
}
int gcd = gcdExtended(b % a, a, out int x1, out int y1);
x = y1 - (b / a) * x1;
y = x1;
return gcd;
}
public static int solve(int a, int b, int x)
{
int fa = a;
if(b < 0)
{
int gcd = gcdExtended(a, x, out fa, out int fb);
fa = fa < 0 ? fa + x : fa;
}
return (int)BigInteger.ModPow(fa, Math.Abs(b), x); // powRussPeas(fa, b, x);
}
passed all tests
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Little Panda Power
You are viewing a single comment's thread. Return to all comments →
C# similar to Java:
passed all tests