Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class Main
- {
- public static void main (String[] args)
- {
- Scanner sc = new Scanner(System.in);
- int A = sc.nextInt();
- int B = sc.nextInt();
- int C = sc.nextInt();
- System.out.println(myPow(A, B, C));
- }
- public static long myPow(int A, int B, int C){
- if(B == 1) return A % C;
- long half = myPow(A, B / 2, C);
- long ret = half * half;
- if(B % 2 == 1) ret = (ret % C) * A;
- return ret % C;
- }
- }
Add Comment
Please, Sign In to add comment