#include <bits/stdc++.h> #include "dzilib.h" using namespace std; #ifdef DEBUG auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;} auto operator<<(auto &o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";} #define debug(X) cerr << "["#X"]: " << X << '\n'; #else #define cerr if(0)cout #define debug(X) ; #endif using ll = long long; #define all(v) (v).begin(), (v).end() #define ssize(x) int(x.size()) #define fi first #define se second #define mp make_pair #define eb emplace_back mt19937_64 rng{420}; int rd(int l, int r) { return rng()%(r-l+1)+l; } int cnt(int num) { int total = 1; for (int i = 2; i*i <= num; i++) { if (num % i == 0) { int e = 0; do { e++; num /= i; } while (num % i == 0); total *= e + 1; } } if (num > 1) { total *= 2; } return total; } unordered_map<int, int> calculated; int get_divs(int a) { return calculated[a] == 0 ? calculated[a] = cnt(a) : calculated[a]; } void solve(ll n, ll c) { vector<int> v; for(int i = 1; i <= n; ++i) v.eb(i); unordered_map<int, bool> used; while(ssize(v) > 1) { int y; while(used[y = rd(0, 1'000'000)]) ; int div = Ask(y); vector<int> new_v; for(auto x : v) if(get_divs(x+y) == div) new_v.eb(x); v = new_v; } if(ssize(v) == 0) Answer(1); else Answer(v[0]); } int main() { int t = GetT(); ll n = GetN(); int q = GetQ(); ll c = GetC(); while (t--) solve(n, c); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | #include <bits/stdc++.h> #include "dzilib.h" using namespace std; #ifdef DEBUG auto&operator<<(auto &o, pair<auto, auto> p) {o << "(" << p.first << ", " << p.second << ")"; return o;} auto operator<<(auto &o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto e : x) o<<e<<", "; return o<<"}";} #define debug(X) cerr << "["#X"]: " << X << '\n'; #else #define cerr if(0)cout #define debug(X) ; #endif using ll = long long; #define all(v) (v).begin(), (v).end() #define ssize(x) int(x.size()) #define fi first #define se second #define mp make_pair #define eb emplace_back mt19937_64 rng{420}; int rd(int l, int r) { return rng()%(r-l+1)+l; } int cnt(int num) { int total = 1; for (int i = 2; i*i <= num; i++) { if (num % i == 0) { int e = 0; do { e++; num /= i; } while (num % i == 0); total *= e + 1; } } if (num > 1) { total *= 2; } return total; } unordered_map<int, int> calculated; int get_divs(int a) { return calculated[a] == 0 ? calculated[a] = cnt(a) : calculated[a]; } void solve(ll n, ll c) { vector<int> v; for(int i = 1; i <= n; ++i) v.eb(i); unordered_map<int, bool> used; while(ssize(v) > 1) { int y; while(used[y = rd(0, 1'000'000)]) ; int div = Ask(y); vector<int> new_v; for(auto x : v) if(get_divs(x+y) == div) new_v.eb(x); v = new_v; } if(ssize(v) == 0) Answer(1); else Answer(v[0]); } int main() { int t = GetT(); ll n = GetN(); int q = GetQ(); ll c = GetC(); while (t--) solve(n, c); return 0; } |