#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a, x, pre, ans, pref = -1, numbers; ll numbs(ll x){ if (x < 10) return 1; return numbs(x / 10) + 1; } ll new_pref_is_bigger(ll previous, ll next){ while (numbs(previous) != numbs(next)) next = next * 10 + 9; return (next >= pref); } int main(){ ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); cin >> a >> pre; for (int i = 0; i < a - 1; i ++){ cout << pre << " " << pref << endl; cin >> x; if (pre < (ll) 1e17){ ll y = x; while (y < pre) y = y * 10 + 9; if (numbs(y) > numbs(pre)){ while (x <= pre){ ans += 1; x *= 10; } } else pre = pre + 1, ans += numbs(pre) - numbs(x); pre = x; } else{ if (pref == -1) pref = pre / (ll) 1e10, numbers = 17; if (new_pref_is_bigger(pref, x)) ans += numbers - numbs(x); else numbers ++, ans += numbers - numbs(x); pref = x / (ll) 1e10; } } cout << ans; 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 | #include <bits/stdc++.h> using namespace std; typedef long long ll; ll a, x, pre, ans, pref = -1, numbers; ll numbs(ll x){ if (x < 10) return 1; return numbs(x / 10) + 1; } ll new_pref_is_bigger(ll previous, ll next){ while (numbs(previous) != numbs(next)) next = next * 10 + 9; return (next >= pref); } int main(){ ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); cin >> a >> pre; for (int i = 0; i < a - 1; i ++){ cout << pre << " " << pref << endl; cin >> x; if (pre < (ll) 1e17){ ll y = x; while (y < pre) y = y * 10 + 9; if (numbs(y) > numbs(pre)){ while (x <= pre){ ans += 1; x *= 10; } } else pre = pre + 1, ans += numbs(pre) - numbs(x); pre = x; } else{ if (pref == -1) pref = pre / (ll) 1e10, numbers = 17; if (new_pref_is_bigger(pref, x)) ans += numbers - numbs(x); else numbers ++, ans += numbers - numbs(x); pref = x / (ll) 1e10; } } cout << ans; return 0; } |