Untitled
unknown
plain_text
2 years ago
570 B
30
Indexable
public class Solution { public int solve(int A, int B) { int P = B - 2; int output = CalculateFermats(A, P, B); return output; } private static int CalculateFermats(int a, int p, int b) { if (p == 0) { return 1; } if ((p & 1) == 1) { return (a * CalculateFermats(((a * a) % b), (p / 2), b)) % b; } else { return CalculateFermats(((a * a) % b), (p / 2), b); } } } Test Case A=12, B=55557209 The expected return value: 32408372 The function returned: 24558423 Please tell me where I did wrong?
Editor is loading...