fork(1) download
  1. /*
  2.   Copyright 2011 Marek "p2004a" Rusinowski
  3.   Exponentiation by squaring
  4. */
  5. #include <cstdio>
  6.  
  7. int pow (int a, int b, int c) {
  8. if (!b) return 1;
  9. int tmp = pow(a, b/2, c);
  10. return (((tmp * tmp) % c) * (b & 1 ? a : 1)) % c;
  11. }
  12.  
  13. int main() {
  14. int a, b, c;
  15. scanf("%d %d %d", &a, &b, &c);
  16. printf("%d\n", pow(a, b, c));
  17. return 0;
  18. }
  19.  
stdin
2 16 1000000
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:15: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout
65536