fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3. long binpow (long a, long n, long m) {
  4. if (n == 0)
  5. return 1 % m;
  6. if (n % 2 == 1)
  7. return (binpow (a, n - 1, m) * a) % m;
  8. else {
  9. return binpow ((a * a) % m, n/2, m);
  10. }
  11. }
  12.  
  13. int main() {
  14. long a, b, m;
  15. cin >> a >> b >> m;
  16. cout << binpow (a, b, m);
  17. return 0;
  18. }
Success #stdin #stdout 0s 15232KB
stdin
9 2 1
stdout
Standard output is empty