CF1665D.GCD Guess

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an interactive problem.

There is a positive integer 1≤x≤1091 \le x \le 10^9 that you have to guess.

In one query you can choose two positive integers a≠ba \neq b. As an answer to this query you will get gcd⁡(x+a,x+b)\gcd(x + a, x + b), where gcd⁡(n,m)\gcd(n, m) is the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest common divisor) of the numbers nn and mm.

To guess one hidden number xx you are allowed to make no more than 3030 queries.

这是一个交互式问题。

存在一个你需要猜测的正整数 1≤x≤1091 \le x \le 10^9。

在一次查询中,你可以选择两个不相等的正整数 a≠ba \neq b。对于该查询,你将得到 gcd⁡(x+a,x+b)\gcd(x + a, x + b),其中 gcd⁡(n,m)\gcd(n, m) 表示数字 nn 和 mm 的[最大公约数](https://en.wikipedia.org/wiki/Greatest common divisor)。

你最多可以进行 3030 次查询来猜出这个隐藏的数 xx。

输入格式

The first line of input contains a single integer tt (1≤t≤10001 \le t \le 1000) denoting the number of test cases.

The integer xx that you have to guess satisfies the constraints: (1≤x≤1091 \le x \le 10^9).

输入的第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。

你需要猜测的整数 xx 满足约束条件:1≤x≤1091 \le x \le 10^9。

输入输出样例

  • 输入#1

    2
    
    1
    
    8
    
    
    1

    输出#1

    ? 1 2
    
    ? 12 4
    
    ! 4
    ? 2000000000 1999999999
    
    ! 1000000000

说明/提示

The first hidden number is 44, that's why the answers for the queries are:

"? 1 2" — gcd⁡(4+1,4+2)=gcd⁡(5,6)=1\gcd(4 + 1, 4 + 2) = \gcd(5, 6) = 1.

"? 12 4" — gcd⁡(4+12,4+4)=gcd⁡(16,8)=8\gcd(4 + 12, 4 + 4) = \gcd(16, 8) = 8.

The second hidden number is 10910^9, that's why the answer for the query is:

"? 2000000000 1999999999" — gcd⁡(3⋅109,3⋅109−1)=1\gcd(3 \cdot 10^9, 3 \cdot 10^9 - 1) = 1.

These queries are made only for understanding the interaction and are not enough for finding the true xx.

第一个隐藏数字是 44,因此各查询的答案为:

"? 1 2" — gcd⁡(4+1,4+2)=gcd⁡(5,6)=1\gcd(4 + 1, 4 + 2) = \gcd(5, 6) = 1。

"? 12 4" — gcd⁡(4+12,4+4)=gcd⁡(16,8)=8\gcd(4 + 12, 4 + 4) = \gcd(16, 8) = 8。

第二个隐藏数字是 10910^9,因此该查询的答案为:

"? 2000000000 1999999999" — gcd⁡(3⋅109,3⋅109−1)=1\gcd(3 \cdot 10^9, 3 \cdot 10^9 - 1) = 1。

这些查询仅用于帮助理解交互过程,并不足以确定真实的 xx。

输入解题思路,AI测评打分。不知道怎么写?

首页