Problem Statement
You are given four positive integers a,b,c and m. Let x = bc. Calculate and return the following value: (ax mod m).
Definition
- Class:
- SimpleMathProblem
- Method:
- calculate
- Parameters:
- int, int, int, int
- Returns:
- int
- Method signature:
- int calculate(int a, int b, int c, int m)
- (be sure your method is public)
Constraints
- a,b,c and m will each be between 1 and 737,373,737, inclusive.
Examples
1
1
1
737
Returns: 1
1^(1^1) modulo 737 is 1.3
7
3
123456789
Returns: 63564408
First we get that x = 7^3 = 343. Then we compute the answer: (3^x modulo 123456789).12
34
56
78
Returns: 66
3737373
7373737
37373
737373737
Returns: 214080347
2
10
10
1024
Returns: 0
2^(10^10) is divisible by 1024, hence the remainder is zero.47
53
912
1
Returns: 0
Any integer modulo 1 is zero.