#include using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair pii; typedef vector vi; const int POPULATION = 10000000; const int ROUNDS = 50; int S = 0; bool sim(int test) { vi R(POPULATION); iota(all(R), 0); rep(i,0,test) { int w = rand() % sz(R); if (R[w] < S) return true; swap(w, R.back()); R.pop_back(); } return false; } int positive(int test) { cout << "test " << test << endl; if (S) { return sim(test); } int x; cin >> x; return x; } vector ls; // log(1) + log(2) + ... + log(x) double logsum(int x) { return ls[x]; } double cond(const vector& res, int guess) { int healthy = POPULATION - guess; double logp = 0; for (auto r : res) { if (r.second == 0 && r.first > healthy) return -DBL_MIN; double phealthy = logsum(healthy) - logsum(healthy - r.first) - logsum(POPULATION) + logsum(POPULATION - r.first); if (r.second == 0) logp += phealthy; else logp += log1p(-exp(phealthy)); } return logp; } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); ls.resize(POPULATION+1); rep(i,1,sz(ls)) { ls[i] = ls[i - 1] + log(i); } rep(i,0,S?100:1) { if (S) S = 1; while (S && (S <= 100 || S >= 5000000)) S = exp(double(rand()) / RAND_MAX * log(POPULATION)); int guess = 100; vector res; rep(it,0,ROUNDS) { if (positive(guess)) { res.emplace_back(guess, 1); guess /= 1.5; if (!guess) ++guess; } else { res.emplace_back(guess, 0); guess *= 1.5; } } guess = 100; double prob = cond(res, guess); for (int i = 150; i < POPULATION/2; i = i * 1.05) { double p = cond(res, i); if (p > prob) { guess = i; prob = p; } } if (S) { assert(S/2 <= guess && guess <= S * 2); cout << "Correct: " << S << " " << guess << endl; } cout << "estimate " << guess << endl; } }