11175 - Big Mod   

Description

Calculate R = (BP) mod M for large B, P, and M. Integer B is in the range 0 to 232 inclusive. Integer P is in the range 0 to 231 inclusive. Integer M is in the range 1 to 65600 inclusive. Note that you cannot calculate R directly because BP is too large.

Input

There are multiple test cases. Each test case is given in three lines, containing B, P, and M in each line.

Case 1: 0 <= B <= 215, 0 <= P <= 215, 1 <= M <= 46340
Case 2: 0 <= B <= 215, 0 <= P <= 231, 1 <= M <= 46340

Case 3: 0 <= B <= 231, 0 <= P <= 231, 1 <= M <= 46340
Case 4: 0 <= B <= 232, 0 <= P <= 231, 1 <= M <= 65600

Output

For each test case, output the answer R in a single line.

Sample Input  Download

Sample Output  Download

Tags




Discuss