import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.util.Scanner;
import java.lang.Math;
class Main
{
public static final boolean DEBUG = false;
public static void main(String[] args) throws IOException
{
Scanner cin;
long x, y;
int k;
int n;
if (DEBUG) {
cin = new Scanner(new BufferedReader(new FileReader("d:\\OJ\\uva_in.txt")));
} else {
cin = new Scanner(System.in);
}
while (cin.hasNext()) {
x = cin.nextLong();
y = cin.nextLong();
k = cin.nextInt();
n = k - 1;
long temp = 1;
while (y > 0) {
if ((y & 1) == 1) {
temp = (temp * x) % n;
}
x = x * x % n;
y >>= 1;
}
if (temp == 0) temp = n;
System.out.println(temp);
}
}
}
题目1085:求root(N, k)
最新推荐文章于 2021-02-25 14:32:42 发布