#include<iostream> #include<vector> #include<stack> #include<algorithm> #include<numeric> #define maxn 100010 #define maxm 51 #define ll long long usingnamespacestd;
constint p = 998244353; inlineintadd(int x, int y){ return (x += y) >= p ? x - p : x; } inlineintmul(int x, int y){ return1ll * x * y % p; } inlineintadd(initializer_list<int> lst){ int s = 0; for (auto t : lst) s = add(s, t); return s; } inlineintmul(initializer_list<int> lst){ int s = 1; for (auto t : lst) s = mul(s, t); return s; }
int pri[maxn], mu[maxn]; bool isp[maxn]; voidinit_isp(int n){ mu[1] = 1; int cnt = 0; for (int i = 2; i <= n; ++i) { if (!isp[i]) pri[++cnt] = i, mu[i] = p - 1; for (int j = 1; j <= cnt && i * pri[j] <= n; ++j) { isp[i * pri[j]] = 1; if (i % pri[j] == 0) break; mu[i * pri[j]] = p - mu[i]; } } }
int n, m, l[maxn], r[maxn];
int dp[maxm][maxn]; int f[maxn];
inlineintget_sum(int k, int l, int r){ if (r < 0) return0; if (l <= 0) return dp[k][r]; return add(dp[k][r], p - dp[k][l - 1]); }
cin >> n >> m; init_isp(m); for (int i = 1; i <= n; ++i) cin >> l[i] >> r[i]; for (int i = 0; i <= m; ++i) dp[0][i] = 1; for (int d = 1; d <= m; ++d) { bool ok = true; if (!mu[d]) continue; for (int i = 1; i <= n; ++i) if ((l[i] + d - 1) / d > r[i]) ok = false; if (!ok) break; for (int i = 1; i <= n; ++i) for (int j = 0; j <= m / d; ++j) { dp[i][j] = get_sum(i - 1, j - r[i] / d, j - (l[i] + d - 1) / d); if (j) dp[i][j] = add(dp[i][j], dp[i][j - 1]); } f[d] = dp[n][m / d]; } int ans = 0; for (int i = 1; i <= m; ++i) ans = add(ans, mul(mu[i], f[i])); cout << ans << "\n"; return0; }