G2. Ruler (hard version)
昨晚的div4最后一题
上一次遇到三分好像是2021年icpc济南,那场2题就能拿银牌:(
/*
* @Author: Hfuubigstrength
* @email: 2854614012@qq.com
* @Date: 2024-08-07 10:52:47
*/
#include <bits/stdc++.h>
// #define int long long
#define PII pair<int,int>
#define LL long long
#define fi first
#define se second
#define debug(a) cout<<#a<<"="<<a<<endl;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define sz(x) (int)x.size()
using namespace std;
void solve(){
// int n;
int l = 2, r = 999;
while(l < r){
int len = (r - l) / 3;
int mid1 = l + len, mid2 = r - len;
cout << "? " << mid1 << " " << mid2 << endl;
int area; cin >> area;
if(mid1 * mid2 == area) l = mid2 + 1;
else if((mid1 + 1) * (mid2 + 1) == area) r = mid1;
else if((mid2 + 1) * mid1 == area) r = mid2, l = mid1 + 1;
}
cout << "! " << l << endl;
}
signed main(){
//ios::sync_with_stdio(false);cin.tie(0);
int tt = 1;
cin >> tt;
while(tt -- ){
solve();
}
return 0;
}
昨晚F用到的组合数预处理:
int fact[N], infact[N];
int qmi(int k, int s, int m){
int res = 1;
while(s){
if(s & 1) res = (LL)res * k % mod;
s >>= 1, k = (LL)k * k % mod;
}
return res;
}
int get(int a, int b){
return (LL)fact[a] * infact[a - b] % mod * infact[b] % mod;
}
void init(){
fact[0] = 1, infact[0] = 1;
for(int i = 1; i <= N - 5; i ++ ){
fact[i] = (LL)fact[i - 1] * i % mod;
infact[i] = (LL)infact[i - 1] * qmi(i, mod - 2, mod) % mod;
}
}