description: Mocha wants to be an astrologer. There are n stars which can be seen in Zhijiang, and the brightness of the i-th star is a_i. 
  
  Mocha considers that these n stars form a constellation, and she uses (a_1,a_2,…,a_n) to show its state. A state is called mathematical if all of the following three conditions are satisfied:
  
    * For all i (1≤ i≤ n), a_i is an integer in the range [l_i, r_i].
    * ∑  _{i=1} ^ n a_i ≤ m.
    * \gcd(a_1,a_2,…,a_n)=1.
  
  
  
  Here, \gcd(a_1,a_2,…,a_n) denotes the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_common_divisor) of integers a_1,a_2,…,a_n.
  
  Mocha is wondering how many different mathematical states of this constellation exist. Because the answer may be large, you must find it modulo 998 244 353.
  
  Two states (a_1,a_2,…,a_n) and (b_1,b_2,…,b_n) are considered different if there exists i (1≤ i≤ n) such that a_i ≠ b_i.
  
  Input
  
  The first line contains two integers n and m (2 ≤ n ≤ 50, 1 ≤ m ≤ 10^5) — the number of stars and the upper bound of the sum of the brightness of stars.
  
  Each of the next n lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ m) — the range of the brightness of the i-th star.
  
  Output
  
  Print a single integer — the number of different mathematical states of this constellation, modulo 998 244 353.
  
  Examples
  
  Input
  
  
  2 4
  1 3
  1 2
  
  
  Output
  
  
  4
  
  Input
  
  
  5 10
  1 10
  1 10
  1 10
  1 10
  1 10
  
  
  Output
  
  
  251
  
  Input
  
  
  5 100
  1 94
  1 96
  1 91
  4 96
  6 97
  
  
  Output
  
  
  47464146
  
  Note
  
  In the first example, there are 4 different mathematical states of this constellation:
  
    * a_1=1, a_2=1.
    * a_1=1, a_2=2.
    * a_1=2, a_2=1.
    * a_1=3, a_2=1.
solution: #include <bits/stdc++.h>
  using namespace std;
  template <typename T>
  T inverse(T a, T m) {
    T u = 0, v = 1;
    while (a != 0) {
      T t = m / a;
      m -= t * a;
      swap(a, m);
      u -= t * v;
      swap(u, v);
    }
    assert(m == 1);
    return u;
  }
  template <typename T>
  class Modular {
   public:
    using Type = typename decay<decltype(T::value)>::type;
    constexpr Modular() : value() {}
    template <typename U>
    Modular(const U& x) {
      value = normalize(x);
    }
    template <typename U>
    static Type normalize(const U& x) {
      Type v;
      if (-mod() <= x && x < mod())
        v = static_cast<Type>(x);
      else
        v = static_cast<Type>(x % mod());
      if (v < 0) v += mod();
      return v;
    }
    const Type& operator()() const { return value; }
    template <typename U>
    explicit operator U() const {
      return static_cast<U>(value);
    }
    constexpr static Type mod() { return T::value; }
    Modular& operator+=(const Modular& other) {
      if ((value += other.value) >= mod()) value -= mod();
      return *this;
    }
    Modular& operator-=(const Modular& other) {
      if ((value -= other.value) < 0) value += mod();
      return *this;
    }
    template <typename U>
    Modular& operator+=(const U& other) {
      return *this += Modular(other);
    }
    template <typename U>
    Modular& operator-=(const U& other) {
      return *this -= Modular(other);
    }
    Modular& operator++() { return *this += 1; }
    Modular& operator--() { return *this -= 1; }
    Modular operator++(int) {
      Modular result(*this);
      *this += 1;
      return result;
    }
    Modular operator--(int) {
      Modular result(*this);
      *this -= 1;
      return result;
    }
    Modular operator-() const { return Modular(-value); }
    template <typename U = T>
    typename enable_if<is_same<typename Modular<U>::Type, int>::value,
                       Modular>::type&
    operator*=(const Modular& rhs) {
      value = normalize(static_cast<int64_t>(value) *
                        static_cast<int64_t>(rhs.value));
      return *this;
    }
    template <typename U = T>
    typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value,
                       Modular>::type&
    operator*=(const Modular& rhs) {
      int64_t q = static_cast<int64_t>(static_cast<long double>(value) *
                                       rhs.value / mod());
      value = normalize(value * rhs.value - q * mod());
      return *this;
    }
    template <typename U = T>
    typename enable_if<!is_integral<typename Modular<U>::Type>::value,
                       Modular>::type&
    operator*=(const Modular& rhs) {
      value = normalize(value * rhs.value);
      return *this;
    }
    Modular& operator/=(const Modular& other) {
      return *this *= Modular(inverse(other.value, mod()));
    }
    template <typename U>
    friend const Modular<U>& abs(const Modular<U>& v) {
      return v;
    }
    template <typename U>
    friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);
    template <typename U>
    friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);
    template <typename U>
    friend std::istream& operator>>(std::istream& stream, Modular<U>& number);
  
   private:
    Type value;
  };
  template <typename T>
  bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) {
    return lhs.value == rhs.value;
  }
  template <typename T, typename U>
  bool operator==(const Modular<T>& lhs, U rhs) {
    return lhs == Modular<T>(rhs);
  }
  template <typename T, typename U>
  bool operator==(U lhs, const Modular<T>& rhs) {
    return Modular<T>(lhs) == rhs;
  }
  template <typename T>
  bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) {
    return !(lhs == rhs);
  }
  template <typename T, typename U>
  bool operator!=(const Modular<T>& lhs, U rhs) {
    return !(lhs == rhs);
  }
  template <typename T, typename U>
  bool operator!=(U lhs, const Modular<T>& rhs) {
    return !(lhs == rhs);
  }
  template <typename T>
  bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) {
    return lhs.value < rhs.value;
  }
  template <typename T>
  Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) {
    return Modular<T>(lhs) += rhs;
  }
  template <typename T, typename U>
  Modular<T> operator+(const Modular<T>& lhs, U rhs) {
    return Modular<T>(lhs) += rhs;
  }
  template <typename T, typename U>
  Modular<T> operator+(U lhs, const Modular<T>& rhs) {
    return Modular<T>(lhs) += rhs;
  }
  template <typename T>
  Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) {
    return Modular<T>(lhs) -= rhs;
  }
  template <typename T, typename U>
  Modular<T> operator-(const Modular<T>& lhs, U rhs) {
    return Modular<T>(lhs) -= rhs;
  }
  template <typename T, typename U>
  Modular<T> operator-(U lhs, const Modular<T>& rhs) {
    return Modular<T>(lhs) -= rhs;
  }
  template <typename T>
  Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) {
    return Modular<T>(lhs) *= rhs;
  }
  template <typename T, typename U>
  Modular<T> operator*(const Modular<T>& lhs, U rhs) {
    return Modular<T>(lhs) *= rhs;
  }
  template <typename T, typename U>
  Modular<T> operator*(U lhs, const Modular<T>& rhs) {
    return Modular<T>(lhs) *= rhs;
  }
  template <typename T>
  Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) {
    return Modular<T>(lhs) /= rhs;
  }
  template <typename T, typename U>
  Modular<T> operator/(const Modular<T>& lhs, U rhs) {
    return Modular<T>(lhs) /= rhs;
  }
  template <typename T, typename U>
  Modular<T> operator/(U lhs, const Modular<T>& rhs) {
    return Modular<T>(lhs) /= rhs;
  }
  template <typename T, typename U>
  Modular<T> power(const Modular<T>& a, const U& b) {
    assert(b >= 0);
    Modular<T> x = a, res = 1;
    U p = b;
    while (p > 0) {
      if (p & 1) res *= x;
      x *= x;
      p >>= 1;
    }
    return res;
  }
  template <typename T>
  bool IsZero(const Modular<T>& number) {
    return number() == 0;
  }
  template <typename T>
  string to_string(const Modular<T>& number) {
    return to_string(number());
  }
  template <typename T>
  std::ostream& operator<<(std::ostream& stream, const Modular<T>& number) {
    return stream << number();
  }
  template <typename T>
  std::istream& operator>>(std::istream& stream, Modular<T>& number) {
    typename common_type<typename Modular<T>::Type, int64_t>::type x;
    stream >> x;
    number.value = Modular<T>::normalize(x);
    return stream;
  }
  constexpr int md = 998244353;
  using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;
  vector<Mint> fact(1, 1);
  vector<Mint> inv_fact(1, 1);
  Mint C(int n, int k) {
    if (k < 0 || k > n) {
      return 0;
    }
    while ((int)fact.size() < n + 1) {
      fact.push_back(fact.back() * (int)fact.size());
      inv_fact.push_back(1 / fact.back());
    }
    return fact[n] * inv_fact[k] * inv_fact[n - k];
  }
  vector<int> smallest_factor;
  vector<int8_t> smallest_power;
  vector<int8_t> mobius;
  vector<bool> prime;
  vector<int> primes;
  void sieve(int maximum) {
    maximum = max(maximum, 1);
    smallest_factor.assign(maximum + 1, 0);
    smallest_power.assign(maximum + 1, 0);
    mobius.assign(maximum + 1, 0);
    prime.assign(maximum + 1, true);
    mobius[1] = 1;
    prime[0] = prime[1] = false;
    primes = {};
    for (int i = 2; i <= maximum; i++) {
      if (prime[i]) {
        smallest_factor[i] = i;
        smallest_power[i] = 1;
        mobius[i] = -1;
        primes.push_back(i);
      }
      for (int p : primes) {
        if (p > smallest_factor[i] || i * p > maximum) break;
        prime[i * p] = false;
        smallest_factor[i * p] = p;
        smallest_power[i * p] =
            smallest_factor[i] == p ? int8_t(smallest_power[i] + 1) : 1;
        mobius[i * p] = smallest_factor[i] == p ? 0 : int8_t(-mobius[i]);
      }
    }
  }
  Mint cal(vector<int> l, vector<int> r, int m) {
    Mint ans = 0;
    int n = r.size();
    for (long long i = 0; i < n; i++) {
      r[i] -= l[i];
      m -= l[i];
    }
    if (m < 0) return 0;
    vector<Mint> sum(m + 1);
    sum[0] = 1;
    for (int ri : r) {
      vector<Mint> sssum(m + 1);
      Mint summ = 0;
      for (int i = 0; i <= m; i++) {
        summ += sum[i];
        summ -= i > ri ? sum[i - ri - 1] : 0;
        sssum[i] = summ;
      }
      sum.swap(sssum);
    }
    for (int i = 0; i <= m; i++) ans += sum[i];
    return ans;
  }
  void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> l(n), r(n);
    for (long long i = 0; i < n; i++) cin >> l[i] >> r[i];
    sieve(100001);
    Mint ans = 0;
    for (int i = 1; i <= m; i++) {
      vector<int> long long(n), rr(n);
      for (int j = 0; j < n; j++) {
        long long[j] = (l[j] + i - 1) / i;
        rr[j] = r[j] / i;
      }
      ans += (Mint)mobius[i] * cal(long long, rr, m / i);
    }
    cout << ans << '\n';
  }
  int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int qq = 1;
    for (int i = 1; i <= qq; i++) {
      solve();
    }
  }
  