Z ans = 0; for (int mask = 0; mask < all; mask++) { Z res = dp[mask]; for (int i = 0; i < 16; i++) { if (mask >> i & 1) { res *= Z(primes[i] - 1) / Z(primes[i]); } } ans += res; } cout << ans << '\n'; }
int cnt1 = 0, cnt2 = 0; for (auto ch : s) cnt1 += ch == '#'; for (auto ch : t) cnt2 += ch == '#';
if (cnt1 == n and cnt2 == n) { cout << "Yes\n"; for (int i = 0; i < 7; i++) { a[i].assign(n, '#'); cout << a[i] << '\n'; } return; }
if (max(cnt1, cnt2) == n and cnt1 != cnt2) { cout << "No\n"; return; }
int l = -1, r = -1;
for (int i = 0; i < n and l == -1; i++) { if (a[1][i] == '#') continue; if (i - 1 >= 0and a[1][i - 1] == '#') l = i; if (i + 1 < n and a[1][i + 1] == '#') l = i; } for (int i = 0; i < n and r == -1; i++) { if (a[5][i] == '#') continue; if (i - 1 >= 0and a[5][i - 1] == '#') r = i; if (i + 1 < n and a[5][i + 1] == '#') r = i; } a[2][l] = a[4][r] = '#';
if (l > r) swap(l, r); if (l == r or l + 1 == r) { a[3][l] = '#'; } else { for (int i = l + 1; i < r; i++) { a[3][i] = '#'; } }
cout << "Yes\n"; for (int i = 0; i < 7; i++) { cout << a[i] << '\n'; } // cerr << "----\n"; }
D. 有限小数
给定两个互质正整数 $a, b$,你需要求两个非负整数 $c, d$,满足以下两个条件:
$\frac{a}{b} + \frac{c}{d}$ 为十进制下的整数或有限小数。
$1 \le d \le 10^9$
在所有满足条件的非负整数对 $(c, d)$ 中,请求出 $c$ 最小的一对。 $1 \le a \le b \le 10^6$
i64 exgcd(i64 a, i64 b, i64 &x, i64 &y){ if (b == 0) { x = 1; y = 0; return a; } i64 g = exgcd(b, a % b, y, x); y -= a / b * x; return g; } // ax + b = 0 (mod m) std::pair<i64, i64> sol(i64 a, i64 b, i64 m){ assert(m > 0); b *= -1; i64 x, y; i64 g = exgcd(a, m, x, y); if (g < 0) { g *= -1; x *= -1; y *= -1; } if (b % g != 0) { return {-1, -1}; } x = x * (b / g) % (m / g); if (x < 0) { x += m / g; } return {x, m / g}; }
voidsolve(){ int a; cin >> a; int b; cin >> b;
int p = b; while (p % 2 == 0) p /= 2; while (p % 5 == 0) p /= 5;
pii ans = {inf, inf};
for (int x : p2) { for (int y : p5) { int d = p * x * y;
if (d > 1'000'000'000) break; auto [c, g] = sol(b, a * d, p * p);
// cout << c << ' ' << d << '\n';
// cout << "bc = " << b * c; // cout << ", ad = " << a * d; // cout << ", p = " << p << '-';
vector<int> ind(n); vector<vector<int>> g(n); for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; u--, v--;
g[u].eb(v), g[v].eb(u); ind[u]++, ind[v]++; }
int ans = 0; pii res = {0, 0}; for (int i = 0; i < n; i++) { if (ind[i] == 1) { if (a[i] >= res.fi) { res = {a[i], res.fi}; } elseif (a[i] > res.se) { res.se = a[i]; } } else ans = max(ans, a[i]); } if (res.se != inf) ans = max(ans, res.se);
cout << ans; }
J 骰子
Code >folded
1 2 3 4 5 6 7 8
voidsolve(){ int n; cin >> n; int m; cin >> m; if (n >= 2and m >= 2) { cout << n * m * 6LL << '\n'; return; } }
K 小 C 的神秘图形
Code >folded
1 2 3 4 5 6 7 8 9 10 11 12 13 14
voidsolve(){ int n; cin >> n; string s, t; cin >> s >> t; for (int i = 0; i < n; i++) { if (s[i] == '1'or t[i] == '1') { continue; } else { cout << "0"; return; } } cout << "1"; }