fork download
  1. #include <limits>
  2. #include <iostream>
  3.  
  4. using U = unsigned char;
  5.  
  6. constexpr U mul(U a, U b) {
  7. U prod = 0;
  8. while (a) {
  9. if (a & 1) prod += b;
  10. a >>= 1;
  11. b <<= 1;
  12. }
  13. return prod;
  14. }
  15.  
  16. int main() {
  17. const U max = std::numeric_limits<U>::max(),
  18. min = std::numeric_limits<U>::min();
  19. if (mul(max, max) != U(max * max))
  20. std::cout << (int)max << ": " << mul(max, max) << ' ' << U(max*max) << '\n';
  21. for (U a = min; a < max; ++a)
  22. for (U b = min; b < max; ++b)
  23. if(mul(a, b) != U(a*b))
  24. std::cout << (int)a << ' ' << (int)b << ": " << mul(a,b) << ' ' << U(a*b) << '\n';
  25. }
Time limit exceeded #stdin #stdout 15s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty