跳到正文

题解

题解:P14750 月影戀

Cloudwake约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年12月16日
收录
2025年12月19日
更新
2026年11月6日
篇幅
约 2 分钟
题目
P14750

版本

  1. v1当前

分析

数学题。

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

设 a=260a=2^{60}。

hh 有上限,gcd⁡(a,b)=a\operatorname{gcd}(a,b)=a 则有 b=ab=a。

设已知的二进制位数为 wsws,并从低到高一步步访问。

为了 b≥0b \ge 0,每次访问 a=260a=2^{60} 和 b=260−wsb=2^{60}-ws。

每次询问将 hh 加到 bb。

算数意义即为 gcd⁡(260,h−ws)\operatorname{gcd}(2^{60},h-ws)。

我们不知道的最后一位。

交互返回 2602^{60},则说明 b=ab=a,输出即可。

代码

C++
#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;
 }
原文