Calculations with Modulo

3.8

5 votes
multiplicative inverse, gcd, Modular arithmetic, Greatest common divisor, Easy, Modular exponentiation, Mathematics, Greatest common divisor, Number theory
Problem

Find the answer of (ABC)%M.

Input:
The only line of input consists of four integers A,B,C and M. The input always has C and M such that gcd(C,M)=1.

Output:
Print the answer as asked in the problem statement.

Constraints:
1A,B,C,M109
gcd(C,M)=1.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

23=8
so, 8/4 = 2
Finally, 2%5 = 2

Editor Image

?