-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathK.cpp
66 lines (51 loc) · 1.08 KB
/
K.cpp
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
//
// Created by Anarsiel on 16/11/2018.
//
#include <iostream>
typedef long long ll;
using namespace std;
ll n;
ll sdvig;
ll MOD(ll x) {
return (x % n + n) % n;
}
int cnt = 0;
ll ask(ll index) {
if (cnt == 10) exit(1);
cout << "? " << index + 1 << endl;
ll value;
cin >> value;
cnt++;
return value;
}
void finish(ll index) {
// if (cnt == 10) exit(1);
cout << "! " << index + 1 << endl;
}
int main() {
ll x, m;
cin >> x >> m;
n = (ll)1e18 - m;
// cout << n << endl;
sdvig = ask(0) - 1; // сдвиг назад
x -= sdvig;
if (x < 1) x += (ll)1e18;
ll l = max(x - m - 2, -1LL), r = min(x + 2, n);
while (l != r - 1) {
ll medium = (l + r) / 2;
ll medium2 = medium;
medium = MOD(medium);
ll value = ask(medium) - sdvig;
if (value < 1) value += (ll)1e18;
if (value > x) {
r = medium2;
} else if (value < x) {
l = medium2;
} else {
finish(medium2);
return 0;
}
}
finish(-2);
return 0;
}