User Tools

Site Tools


prelude_two_to_carmichael_numbers_--_efficient_power_mod

This is an old revision of the document!


Prelude to Carmichael Numbers -- Efficient Power Mod

First, start by reading the problem statement for Carmichael Numbers.

For this prelude, you are to a power of one number modulo another number.

Input

Input consists of a sequence of lines, with each line containing three integers, a, n, and p (each less than 65000), separated by spaces. The last line contains three 0s, which should not be processed.

Output

For each dataset, compute a ^ n mod p, printing the result in the format shown below.

Sample Input

3 2 2
5 3 7
4 13 497
0

Sample Output

3 ^ 2 mod 2 is 1.
5 ^ 3 mod 7 is 6.
4 ^ 13 mod 497 is 445.
prelude_two_to_carmichael_numbers_--_efficient_power_mod.1316958765.txt.gz · Last modified: 2011/09/25 06:52 by jtkorb