Limits 2s, 512 MB

You will be given three integers a, b, m. Print ( ab ) mod m. There will be 30 test cases at most in an input file. In each case a and b both will be integer numbers of at most 105 digits.

Input

There will be multiple test cases in each input file . Each line of the input file will contain three integer numbers a , b and m (1 ≤ m ≤ 1.5*109).

a and b both will be integer numbers of at most 105 digits.
Input will be terminated when a = 0 , b = 0 and m = 0. This line should not be processed.
Each input file contains 30 test cases at most.

Output

For each case, print ( ab ) mod m in a new line.

Sample

InputOutput
7 2 11
4 2 3
19 1 5
0 0 0
5
1
4

Submit

Login to submit.

Statistics

24% Solution Ratio
IOI_StfuFfsEarliest, Mar '18
tahoangquan2Fastest, 0.1s
Tarik.amtolyLightest, 262 kB
Nusab19Shortest, 74B
Toph uses cookies. By continuing you agree to our Cookie Policy.