题目1085:求root(N, k)

来源:互联网 发布:改图宝软件下载 编辑:程序博客网 时间:2024/05/22 11:48
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);}}}

0 0