ll ceil(ll n, ll m){ if (n >= 0) return (n + m - 1) / m; elsereturn n / m; }
ll floor(ll n, ll m){ if (n >= 0) return n / m; elsereturn (n - m + 1) / m; }
voidsolve(){ ll n, k; cin >> n >> k; ll p = 1; while (p + ceil(p, k - 1) <= n) { ll r = ceil(p, k - 1); ll a = min(floor((k - 1) * r - p, r) + 1, (n - p) / r); p += a * r; } cout << p << endl; }
#include<bits/stdc++.h> usingnamespace std; using ll = longlong; using ull = unsignedlonglong;
constexprunsigned N = 250;
intmain(){ int n, k; cin >> n >> k; vector<vector<int>> adj(n); for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; u--, v--; adj[u].push_back(v); adj[v].push_back(u); }
vector<int> parent(n, -1); vector<int> dep(n); [&](thisauto&& dfs, int x) -> void { for (auto y : adj[x]) { if (y == parent[x]) { continue; } parent[y] = x; dep[y] = dep[x] + 1; dfs(y); } } (0);
vector<bitset<N>> eqs; vector<pair<int, int>> query; array<bitset<N>, N> ha{}; array<int, N> hc{}; auto insert = [&](bitset<N> a, int c) { for (int bit = 0; bit < N; bit++) { if (a.test(bit)) { if (!ha[bit].any()) { for (int rua = bit + 1; rua < N; rua++) { if (ha[rua].any() && a.test(rua)) { a ^= ha[rua]; c ^= hc[rua]; } } for (int rua = 0; rua < bit; rua++) { if (ha[rua].test(bit)) { ha[rua] ^= a; hc[rua] ^= c; } } ha[bit] = a; hc[bit] = c; returntrue; } a ^= ha[bit]; c ^= hc[bit]; } } returnfalse; }; { bitset<N> eq; eq.set(0); insert(eq, 0); } for (int x = 0; x < n; x++) { for (int y = 0; y < n; y++) { int u = x, v = y; bitset<N> eq; while (u != v) { if (dep[u] < dep[v]) { swap(u, v); } eq.set(u); u = parent[u]; } eq.set(u); // LCA 也要放进去 if (eq.count() != k + 1) { // 注意 k 是边数 eq 是点数 continue; } if (insert(eq, 0)) { eqs.push_back(eq); query.push_back({x, y}); } } }
assert(eqs.size() <= n - 1); if (eqs.size() < n - 1) { cout << "NO" << endl; return; }
cout << "YES" << endl; cout << "? " << n - 1; for (auto [x, y] : query) { cout << " " << x + 1 << " " << y + 1; } cout << endl;
voidsolve(){ int n, m; cin >> n >> m; int cur = 0; vector a(n, vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { a[i][j] = cur++; } if (m % 2 == 1 && i % 2 == 1) { rotate(a[i].begin(), a[i].begin() + 1, a[i].end()); } }
cout << "YES" << "\n"; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cout << a[i][j] + 1 << " \n"[j == m - 1]; } } }