2022-04-09 16:24阅读: 113评论: 0推荐: 0

Codeforces Round #781 D. GCD Guess

传送门

题目大意

交互题,每次询问给出 a,b , 得到 gcd(x+a,x+b)(1x109,1a,b2×109)30 次询问内求出 x

思路

考虑通过回答来确定 x 二进制上每一位的值,我们每次可以记录 0i 位的答案为 ansi ,查询 gcd(xansi+2i+1,xansi+2i+1+2i+2)=gcd(xansi+2i+1,2i+2) 来确定第 i+1 位的值,如果得到的回答 2i+2 ,那么第 i+1 位就为 1 ,否则为 0

代码

#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using TP = tuple<int, int, int>;
#define all(x) x.begin(),x.end()
//#define int LL
//#define lc p*2
//#define rc p*2+1
//#define endl '\n'
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
//#pragma warning(disable : 4996)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
const double eps = 1e-8;
const LL MOD = 1000000007;
const LL mod = 998244353;
const int maxn = 200010;

LL T, A[35];

void solve()
{
	LL res, ans = 0;
	for (int i = 0; i < 30; i++)
	{
		LL a = A[i] - ans, b = A[i] + A[i + 1] - ans;
		cout << "? " << a << ' ' << b << endl;
		cin >> res;
		if (res == A[i + 1])
			ans ^= (1LL << i);
	}
	cout << "! " << ans << endl;
}

int main()
{
	IOS;
	LL num = 1;
	for (int i = 0; i <= 30; i++)
		A[i] = num, num *= 2;
	cin >> T;
	while (T--)
		solve();

	return 0;
}

本文作者:Prgl

本文链接:https://www.cnblogs.com/Prgl/p/16122445.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Prgl  阅读(113)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
展开