Guest User

Untitled

a guest
Oct 17th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class Main
  4. {
  5. public static void main (String[] args)
  6. {
  7. Scanner sc = new Scanner(System.in);
  8. int A = sc.nextInt();
  9. int B = sc.nextInt();
  10. int C = sc.nextInt();
  11. System.out.println(myPow(A, B, C));
  12. }
  13.  
  14. public static long myPow(int A, int B, int C){
  15. if(B == 1) return A % C;
  16. long half = myPow(A, B / 2, C);
  17. long ret = half * half;
  18. if(B % 2 == 1) ret = (ret % C) * A;
  19. return ret % C;
  20. }
  21. }
Add Comment
Please, Sign In to add comment