Logo
(追記) (追記ここまで)

18617번 - From Modular to Rational 다국어인터랙티브

시간 제한메모리 제한제출정답맞힌 사람정답 비율
20 초 256 MB3712836.364%

문제

This is an interactive problem.

Someone picked a positive rational number $x=p/q$ where 1ドル \leq p, q \leq 10^9$. You may ask at most 10ドル$ queries of the kind "? $m$", where 10ドル^9 < m < 10^{12}$ and $m$ is a prime number. For each query, you will get the number $y$ such that $y \equiv pq^{-1} \pmod{m}$. You have to guess the number $x$.

입력

출력

제한

프로토콜

The first line of input contains a single integer $t,ドル the number of test cases (1ドル \leq t \leq 10^5$).

For each test case, you may ask at most 10ドル$ queries. Each query should be one of two types:

  • "? $m$", where 10ドル^9 < m < 10^{12}$ and $m$ is a prime number,
  • "! $p$ $q$", where 1ドル \leq p, q \leq 10^9,ドル meaning that the answer is equal to $p/q$.

It is guaranteed that the number $x$ in each test case does not change during testing.

예제 입력 1

3
1
500000004
2

예제 출력 1

? 1000000007
! 1 1
? 1000000007
! 2 4
? 1000000007
! 2 1

힌트

In the example, you deal with $x=1/1,ドル $x=1/2,ドル and $x=2/1,ドル while always taking $m=10^9+7$.

As you may see, it is not necessary to have $\gcd(p,q)=1$ as long as 1ドル\leq p,q\leq 10^9$ and $x=p/q$.

출처

Camp > Petrozavodsk Programming Camp > Summer 2019 > Day 4: Oleksandr Kulkov Contest 2 I번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /