Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class ModPow{
- public static void main(String args[]){
- Scanner sc = new Scanner(System.in);
- int base = sc.nextInt();
- int exp = sc.nextInt();
- int n = sc.nextInt();
- //base^exp % n
- base %= n;
- int result = 1;
- while(exp>0){
- if((exp & 1)==1)
- result = (result*base) % n;
- base = (base * base) % n;
- exp >>= 1;
- }
- System.out.println(result);
- }
- }
Add Comment
Please, Sign In to add comment