fork(2) download
  1. #include <string>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. using int128 = signed __int128;
  6. using uint128 = unsigned __int128;
  7.  
  8. namespace int128_io {
  9.  
  10. inline auto char_to_digit(int chr) {
  11. return static_cast<int>(isalpha(chr) ? 10+tolower(chr)-'a': chr-'0'); }
  12.  
  13. inline auto digit_to_char(int digit) {
  14. return static_cast<char>(digit > 9 ? 'a'+digit-10: '0'+digit); }
  15.  
  16. template<class integer>
  17. inline auto to_int(const std::string &str, size_t *idx = nullptr, int base = 10) {
  18. size_t i = idx != nullptr ? *idx : 0;
  19. const auto n = str.size();
  20. const auto neg = str[i] == '-';
  21. integer num = 0;
  22. if (neg)
  23. ++i;
  24. while (i < n)
  25. num *= base, num += char_to_digit(str[i++]);
  26. if (idx != nullptr)
  27. *idx = i;
  28. return neg ? -num : num; }
  29.  
  30. template<class integer>
  31. inline auto to_string(integer num, int base = 10) {
  32. const auto neg = num < 0;
  33. std::string str;
  34. if (neg)
  35. num = -num;
  36. do
  37. str += digit_to_char(num%base), num /= base;
  38. while (num > 0);
  39. if (neg)
  40. str += '-';
  41. std::reverse(str.begin(),str.end());
  42. return str; }
  43.  
  44. inline auto next_str(std::istream &stream) { std::string str; stream >> str; return str; }
  45.  
  46. template<class integer>
  47. inline auto& read(std::istream &stream, integer &num) {
  48. num = to_int<integer>(next_str(stream));
  49. return stream; }
  50.  
  51. template<class integer>
  52. inline auto& write(std::ostream &stream, integer num) { return stream << to_string(num); } }
  53.  
  54. using namespace std;
  55.  
  56. inline auto& operator>>(istream &stream, int128 &num) { return int128_io::read(stream,num); }
  57. inline auto& operator>>(istream &stream, uint128 &num) { return int128_io::read(stream,num); }
  58. inline auto& operator<<(ostream &stream, int128 num) { return int128_io::write(stream,num); }
  59. inline auto& operator<<(ostream &stream, uint128 num) { return int128_io::write(stream,num); }
  60.  
  61. inline auto uint128_max() {
  62. uint128 ans = 0;
  63. for (uint128 pow = 1; pow > 0; pow <<= 1)
  64. ans |= pow;
  65. return ans; }
  66.  
  67. int main() {
  68. int128 x, y;
  69. if (cin >> x >> y, cout << x << " + " << y << " = " << x+y << endl, x > y)
  70. cout << x << " > " << y << endl;
  71. else
  72. cout << x << " <= " << y << endl;
  73. cout << "maximum unsigned 128-bit integer 2**128 - 1 = " << uint128_max(); }
  74.  
Success #stdin #stdout 0.01s 5304KB
stdin
10000000000000000000000000 -20000000000000000000000000
stdout
10000000000000000000000000 + -20000000000000000000000000 = -10000000000000000000000000
10000000000000000000000000 > -20000000000000000000000000
maximum unsigned 128-bit integer 2**128 - 1 = 340282366920938463463374607431768211455