inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
inlinevoidwork(){ int n = rd(), ans = rd(); for (int i = 2; i <= n; ++i) ans = (ans & rd()); printf("%d\n", ans); }
intmain(){ for (int t = rd(); t; --t) work(); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 1007
char s[N];
inlinevoidwork(){ int n = rd(); scanf("%s", s + 1); int l = 1, r = n; while (s[l] == '?' && l <= n) ++l; if (l == n + 1) { for (int i = 1; i <= n; ++i) putchar((i & 1) ? 'B' : 'R'); puts(""); return; } for (int i = l - 1; i; --i) s[i] = (s[i + 1] == 'R' ? 'B' : 'R'); while (s[r] == '?' && r) --r; for (int i = r + 1; i <= n; ++i) s[i] = (s[i - 1] == 'R' ? 'B' : 'R'); for (int i = l; i <= r; ++i) if (s[i] == '?') s[i] = (s[i - 1] == 'R' ? 'B' : 'R'); puts(s + 1); }
intmain(){ for (int t = rd(); t; --t) work(); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 10007
int a[N];
inlinevoidwork(){ int n = rd(); for (int i = 1; i <= n; ++i) a[i] = rd(); if (a[1] == 1) { printf("%d ", n + 1); for (int i = 1; i <= n; ++i) printf("%d ", i); puts(""); return; } if (a[n] == 0) { for (int i = 1; i <= n; ++i) printf("%d ", i); printf("%d\n", n + 1); return; } for (int i = 1; i <= n; ++i) if (a[i] == 0 && a[i + 1] == 1) { for (int j = 1; j <= i; ++j) printf("%d ", j); printf("%d ", n + 1); for (int j = i + 1; j <= n; ++j) printf("%d ", j); puts(""); return; } }
intmain(){ for (int t = rd(); t; --t) work(); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 100007
structDSU { int f[N]; inlinevoidreset(int n){for (int i = 1; i <= n; ++i) f[i] = i;} intfind(int x){return x == f[x] ? x : f[x] = find(f[x]);} inlineboolmerge(int x, int y){ x = find(x); y = find(y); return x == y ? false : (f[x] = y, true); } } A, B;
vector<int> sA, sB;
vector<pii> res;
intmain(){ int n = rd(), m1 = rd(), m2 = rd(); A.reset(n); B.reset(n); while (m1--) A.merge(rd(), rd()); while (m2--) B.merge(rd(), rd()); for (int j = 1; j <= n; ++j) if (A.find(1) != A.find(j) && B.find(1) != B.find(j)) { res.push_back(make_pair(1, j)); A.merge(1, j); B.merge(1, j); } for (int i = 1; i <= n; ++i) { if (A.find(1) != A.find(i)) sA.push_back(i); if (B.find(1) != B.find(i)) sB.push_back(i); } while (!sA.empty() && !sB.empty()) { int u = sA.back(), v = sB.back(); sA.pop_back(); sB.pop_back(); res.push_back(make_pair(u, v)); A.merge(u, v); B.merge(u, v); while (!sA.empty() && A.find(1) == A.find(sA.back())) sA.pop_back(); while (!sB.empty() && B.find(1) == B.find(sB.back())) sB.pop_back(); } printf("%d\n", (int)res.size()); for (auto [u, v] : res) printf("%d %d\n", u, v); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 51 #define M 100007 #define mod 998244353
int l[N], r[N], f[N][M], sum[N][M], ans[M];
intmain(){ int n = rd(), m = rd(); for (int i = 1; i <= n; ++i) {l[i] = rd(); r[i] = rd();}
for (int j = 0; j <= m; ++j) sum[0][j] = 1; auto mo = [&](int x) {return x >= mod ? x - mod : x;}; auto dp = [&](int t, int d) { for (int i = 1; i <= n; ++i) { int L = (l[i] + d - 1) / d, R = r[i] / d; for (int j = 1; j <= t; ++j) f[i][j] = 0; for (int j = L; j <= t; ++j) f[i][j] = mo(mod + sum[i - 1][j - L] - (j - R - 1 >= 0 ? sum[i - 1][j - R - 1] : 0)); for (int j = 1; j <= t; ++j) sum[i][j] = mo(sum[i][j - 1] + f[i][j]); } return sum[n][t]; }; int lim = m / n; for (int d = lim; d; --d) { ans[d] = dp(m / d, d); for (int i = d * 2; i <= lim; i += d) ans[d] = mo(ans[d] + mod - ans[i]); } printf("%d\n", ans[1]); return0; }
inlineintrd(){ int x = 0; bool f = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) f |= (c == '-'); for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48); return f ? -x : x; }
#define N 51 #define M 100007 #define mod 998244353
int l[N], r[N], f[N][M], sum[N][M];
int prm[M], mnd[M], mu[M] = {0, 1};
intmain(){ int n = rd(), m = rd(); for (int i = 1; i <= n; ++i) {l[i] = rd(); r[i] = rd();} for (int i = 2; i <= m; ++i) { if (!mnd[i]) {prm[++prm[0]] = mnd[i] = i; mu[i] = mod - 1;} for (int j = 1, p = prm[1], prod; j <= prm[0]; p = prm[++j]) { if ((prod = i * p) > m) break; mnd[prod] = p; if (p == mnd[i]) {mu[prod] = 0; break;} mu[prod] = 1ll * mu[i] * mu[p] % mod; } }
for (int j = 0; j <= m; ++j) sum[0][j] = 1; auto mo = [&](int x) {return x >= mod ? x - mod : x;}; auto dp = [&](int t, int d) { for (int i = 1; i <= n; ++i) { int L = (l[i] + d - 1) / d, R = r[i] / d; for (int j = 1; j <= t; ++j) f[i][j] = 0; for (int j = L; j <= t; ++j) f[i][j] = mo(mod + sum[i - 1][j - L] - (j - R - 1 >= 0 ? sum[i - 1][j - R - 1] : 0)); for (int j = 1; j <= t; ++j) sum[i][j] = mo(sum[i][j - 1] + f[i][j]); } return sum[n][t]; }; int ans = 0; for (int d = 1; d <= m / n; ++d) ans = (ans + 1ll * mu[d] * dp(m / d, d)) % mod; printf("%d\n", ans); return0; }