1 import java.io.*;
 2 import java.math.*;
 3 import java.util.*;
 4 import java.text.*;
 5 
 6 public class Main {
 7     public static void main(String[] args) {
 8         Scanner cin = new Scanner(System.in);
 9         BigInteger a, b, m, ans;
10         while (cin.hasNext()) {
11             ans = new BigInteger("1");
12             a = cin.nextBigInteger();
13             b = cin.nextBigInteger();
14             m = cin.nextBigInteger();
15             a = a.mod(m);
16             while (b.compareTo(new BigInteger("0")) > 0) {
17                 if (b.mod(BigInteger.valueOf(2)).compareTo(BigInteger.ONE) == 0) // if(n%2==1)
18                     ans = ans.multiply(a).mod(m); // sq=(sq*p)%m;
19                 a = a.multiply(a).mod(m); // p=(p*p)%m;
20                 b = b.divide(BigInteger.valueOf(2));
21             }
22             System.out.println(ans);
23         }
24     }
25 }

相关文章:

  • 2022-01-04
  • 2018-07-24
  • 2021-07-22
  • 2021-11-07
  • 2021-11-12
  • 2022-12-23
  • 2021-12-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-17
  • 2022-01-13
  • 2021-09-14
  • 2021-09-30
  • 2022-12-23
相关资源
相似解决方案