fork(2) download
  1. #include <iostream>
  2.  
  3. typedef unsigned long long BIG;
  4. BIG mod_multiply( BIG A, BIG B, BIG C )
  5. {
  6. BIG mod_product = 0;
  7. // A %= C; may or may not help performance
  8. B %= C;
  9.  
  10. while (A) {
  11. if (A & 1) {
  12. mod_product += B;
  13. if (mod_product > C) mod_product -= C;
  14. }
  15. A >>= 1;
  16. B <<= 1;
  17. if (B > C) B -= C;
  18. }
  19.  
  20. return mod_product;
  21. }
  22.  
  23. int main()
  24. {
  25. uint64_t retval = mod_multiply( 19010000000000000000, 1011000000000000, 1231231231231211 );
  26. std::cout << retval << "\n";
  27. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
946004848926081