fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27. //* Change this to false => before submitting to cf
  28. // bool testing = true;
  29. bool testing = false;
  30.  
  31.  
  32. int missing;
  33.  
  34. void hack(){
  35. cin >> missing;
  36. if(missing < 2 || missing > 999){
  37. cout << "Invalid missing" << endl;
  38. }
  39. }
  40.  
  41. int interactor(int x, int y){
  42. if(x>=missing) x++;
  43. if(y>=missing) y++;
  44. return x*y;
  45. }
  46.  
  47.  
  48.  
  49. int askQuery(int x, int y){
  50. cout << "? " << x << " " << y << endl;
  51.  
  52. if(testing){
  53. cout << interactor(x, y) << endl;
  54. return interactor(x,y);
  55. }
  56. int area;
  57. cin >> area;
  58. return area;
  59. }
  60.  
  61.  
  62. int consistency(){
  63.  
  64. if(testing){
  65. hack();
  66. }
  67.  
  68.  
  69. int s = 2, e = 999;
  70. while(s<e){
  71. int m1 = s + (e-s)/3;
  72. int m2 = e - (e-s)/3;
  73.  
  74. int res = askQuery(m1, m2);
  75.  
  76. if(res == m1*m2){
  77. s = m2+1;
  78. }
  79. else if(res == m1*(m2+1)){
  80. s = m1+1;
  81. e = m2;
  82. }
  83. else{
  84. e = m1;
  85. }
  86. }
  87.  
  88. return s;
  89. }
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. void solve() {
  99.  
  100. int ans = consistency();
  101. cout << "! " << ans << endl;
  102.  
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109. int32_t main() {
  110. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  111.  
  112. int t = 1;
  113. cin >> t;
  114. while(t--){
  115. solve();
  116. }
  117.  
  118.  
  119. return 0;
  120. }
Success #stdin #stdout 0s 5320KB
stdin
1
5
stdout
? 334 667
223780
? 112 224
25425
? 38 76
3003
? 14 26
405
? 6 10
77
? 3 5
18
? 4 5
24
! 5