// D // DeP #include<cmath> #include<cstdio> #include<cstring>
constexprint MAXN = 1e6 + 5;
int n, K; char str[MAXN];
int A[MAXN];
intcheck(int p){ for (int k = 1; A[p] + k <= 9; ++k) if (abs(A[p] + k - A[p - 1]) != K) return k; return-1; }
intmain(){ int Ti; scanf("%d", &Ti); while (Ti--) { scanf("%s%d", str + 1, &K);
n = strlen(str + 1); A[0] = 0; for (int i = 1; i <= n; ++i) A[i] = str[i] - '0';
int p = -1; for (int i = 2; i <= n && p < 0; ++i) if (abs(A[i - 1] - A[i]) == K) p = i; if (p < 0) p = n; while (p > 1 && check(p) < 0) --p; int d = check(p); A[p] += (d < 0 || p == 1)? 1: d; for (int i = p; i >= 1; --i) if (A[i] > 9) A[i - 1] += A[i] / 10, A[i] %= 10; for (int i = (A[0] > 0)? 1: p + 1; i <= n; ++i) A[i] = (A[i - 1] == K);
for (int i = (A[0] == 0); i <= n; ++i) putchar(A[i] + '0'); putchar('\n'); } return0; }
int n, m, s, e, st, ed; int A[MAXN][MAXN]; pii S[MAXM], E[MAXM];
inlineintidx(int x, int y){ return (x - 1) * m + y; }
namespace DSU { int fa[MAXM], size[MAXM];
voidinit(){ for (int i = 1; i <= n * m + 2; ++i) fa[i] = i, size[i] = 1; }
intfindfa(int u){ return (fa[u] == u)? u: fa[u] = findfa(fa[u]); } inlinevoidjoin(int u, int v){ int fu = findfa(u), fv = findfa(v); if (fu == fv) return; if (size[fu] < size[fv]) swap(fu, fv); fa[fv] = fu, size[fu] += size[fv]; } }
intmain(){ int Ti; scanf("%d", &Ti); while (Ti--) { scanf("%d%d", &n, &m); scanf("%d", &s); for (int i = 1; i <= s; ++i) scanf("%d%d", &S[i].first, &S[i].second); scanf("%d", &e); for (int i = 1; i <= e; ++i) scanf("%d%d", &E[i].first, &E[i].second); int mx = 0; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) scanf("%d", A[i] + j), mx = max(mx, A[i][j]);
st = n * m + 1, ed = n * m + 2; int ans = 1, k = 0; while (ans <= mx) ans <<= 1, ++k; while (k >= 0) { DSU::init(); for (int i = 1; i <= s; ++i) { int x = S[i].first, y = S[i].second; if ((A[x][y] & ans) == ans) DSU::join(st, idx(x, y)); } for (int i = 1; i <= e; ++i) { int x = E[i].first, y = E[i].second; if ((A[x][y] & ans) == ans) DSU::join(ed, idx(x, y)); } for (int x = 1; x <= n; ++x) for (int y = 1; y <= m; ++y) if ((A[x][y] & ans) == ans) { for (int d = 0; d < 2; ++d) { int nx = x + dx[d], ny = y + dy[d]; if (nx <= n && ny <= m && ((A[nx][ny] & ans) == ans)) DSU::join(idx(x, y), idx(nx, ny)); } } if (DSU::findfa(st) == DSU::findfa(ed)) { if (--k >= 0) ans ^= (1 << k); } else { ans ^= (1 << (k--)); if (k >= 0) ans ^= (1 << k); } } printf("%d\n", ans); } return0; }
// H // DeP #include<cstdio> #include<vector> #include<algorithm> usingnamespace std;
typedeflonglong LL; const LL P = 998244353;
intmain(){ int n, C; scanf("%d%d", &n, &C);
int N = max(n, C); vector<LL> inv(N + 1), fac(N + 1), ifac(N + 1); inv[1] = 1; for (int i = 2; i <= N; ++i) inv[i] = inv[P % i] * (P - P / i) % P; fac[0] = ifac[0] = 1; for (int i = 1; i <= N; ++i) fac[i] = i * fac[i - 1] % P, ifac[i] = inv[i] * ifac[i - 1] % P;
auto binom = [&](int x, int y) { return fac[x] * ifac[y] % P * ifac[x - y] % P; };
LL ans = 0; for (int x = 1; x <= C; ++x) { auto factor = [](int v) { vector<int> ret; for (int d = 2; d * d <= v; ++d) if (v % d == 0) { ret.push_back(0); while (v % d == 0) ++ret.back(), v /= d; } if (v > 1) ret.push_back(1); return ret; }; vector<int> fc = factor(x); auto f = [&](int c) { LL ret = 0; for (int k = 0; k <= min(c, n - 1); ++k) ret = (ret + binom(c, k) * binom(n - 1, k) % P) % P; return ret; }; LL t = 1; for (auto c: fc) t = t * f(c) % P; ans = (ans + t) % P; } printf("%lld\n", ans); return0; }