import java.util.Scanner; public class SquareMultiply { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println("======= a^b mod p °è»ê ======="); System.out.print("a = "); int a = s.nextInt(); System.out.print("b = "); int b = s.nextInt(); System.out.print("p = "); int p = s.nextInt(); long x=1; long y=a; while(b > 0){ if(b%2 == 1){ x=(x*y)%p; } y = (y*y)%p; // squaring the base b /= 2; } long ans=x%p; System.out.print("´ä = "+ans); } }