fork download
  1. #include<stdio.h>
  2.  
  3. int exp_mod(int b,int w, int p){
  4. //compute b raised to the w-th power mod p
  5. int result=1;
  6.  
  7. while (w>0){
  8. if (w%2) result*=b;
  9. result%=p;
  10. b*=b;
  11. b%=p;
  12. w/=2;
  13. }
  14. return result;
  15. }
  16.  
  17. int main()
  18. {
  19. printf("%d\n", exp_mod(2, 10, 7));
  20. return 0;
  21. }
Success #stdin #stdout 0s 1720KB
stdin
Standard input is empty
stdout
2