fork download
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. int multiply(int a, int b)
  5. {
  6. int result = 0;
  7. int shift = 0;
  8. while(b)
  9. {
  10. result ^= (a * (b & 1)) << shift;
  11. b >>= 1;
  12. shift++;
  13. }
  14. return result;
  15. }
  16.  
  17. int main()
  18. {
  19. std::string line;
  20. while(getline(std::cin, line))
  21. {
  22. std::stringstream ss(line);
  23. int a, b;
  24. ss >> a >> b;
  25. std::cout << a << '@' << b << " = " << multiply(a, b) << std::endl;
  26. }
  27. }
Success #stdin #stdout 0s 15240KB
stdin
5 9
1 2
9 0
6 1
3 3
2 5
7 9
13 11
5 17
14 13
19 1
63 63
stdout
5@9 = 45
1@2 = 2
9@0 = 0
6@1 = 6
3@3 = 5
2@5 = 10
7@9 = 63
13@11 = 127
5@17 = 85
14@13 = 70
19@1 = 19
63@63 = 1365