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