#include <iostream> using namespace std; int main() { int a, b , p; cin >> a >> b >> p; int res = 1 % p; while(b) { if(b&1) res = res * 1ll * a % p; a = a * 1ll * a % p; b >>= 1; } cout << res << endl; return 0; }
import java.util.*; class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); long a = sc.nextLong(); long b = sc.nextLong(); long p = sc.nextLong(); long res = 1 % p; while(b != 0) { if((b&1) != 0) res = res * a % p; a = a * a % p; b >>= 1; } System.out.print(res%p); } }