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