题解:P14750 月影戀

· · 题解

分析

数学题。

因为 \operatorname{lowbit}(h) 所有高位一定是 h 的正整数倍。高位受限不可取多。故有对于 h<2^{60},则 \operatorname{gcd}(2^{60},h)=\operatorname{lowbit}(h)。

设 a=2^{60}。

设已知的二进制位数为 $ws$,并从低到高一步步访问。 为了 $b \ge 0$,每次访问 $a=2^{60}$ 和 $b=2^{60}-ws$。 每次询问将 $h$ 加到 $b$。 算数意义即为 $\operatorname{gcd}(2^{60},h-ws)$。 我们不知道的最后一位。 交互返回 $2^{60}$,则说明 $b=a$,输出即可。 ### 代码 ```cpp #include<bits/stdc++.h> using namespace std; int main() { long long ws=0,c=1152921504606846976,g,t; cin>>t; while(t--) { ws=0,g=0; while(g!=c) { ws+=g; cout<<"? "<<c<<" "<<c-ws<<endl; cout.flush(); cin>>g; cout.flush(); } cout<<"! "<<ws<<endl; } return 0; } ```