CF BUDDY
← Problems·

1665D · GCD Guess

2000 · bitmasks, chinese remainder theorem, constructive algorithms

Problem: This is an interactive problem.

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

In one query you can choose two positive integers aba \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 of the numbers nn and mm.

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

Input Format: The first line of input contains a single integer tt (1t10001 \le t \le 1000) denoting the number of test cases.

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

Note: 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(3109,31091)=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.

Sample Cases

Case 1

Input

2

1

8


1

Output

? 1 2

? 12 4

! 4
? 2000000000 1999999999

! 1000000000

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback