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

34494번 - Inverse Knapsack 서브태스크스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 256 MB1000.000%

문제

For his number theory homework, Busy Beaver is given $T$ pairs of a large prime $p$ and an integer $x$. For each pair, Busy Beaver needs to find a subset of $\{1,\frac 12,\frac 13,\cdots,\frac 1{5000}\}$ of size at most $S$ whose sum is equal to $x$ modulo $p$. Can you help him find such subsets?

A rational number $\frac ab$ is equal to $x$ modulo $p$ if $a \equiv bx \pmod p$.

입력

The first line contains two integers $T$ and $S$ (1ドル \le T \le 1000,ドル 150ドル \le S \le 5000$), indicating the number of testcases and the maximum size of the subset.

Each of the next $T$ lines contains two integers $p$ and $x$ (10ドル^8 \le p \le 10^{18},ドル 0ドル \le x \le p-1$), where $p$ is prime.

출력

For each testcase, output one line indicating the answer. Start with some integer $k$ (0ドル \le k \le S$), indicating the size of the subset, and then follow with $k$ distinct integers $a_1,\dots,a_k$ in increasing order (1ドル \le a_1 < a_2 < \dots < a_k \le 5000$).

Your output should satisfy $\frac{1}{a_1} + \frac{1}{a_2} + \dots + \frac{1}{a_k} \equiv x \pmod p$.

It can be proven that for all $p,ドル $x$ satisfying the input constraints, such a subset always exists.

제한

서브태스크

번호배점제한
110

$T \le 10,ドル $p \le 10^9$.

220

$T \le 10,ドル $p \le 10^{15},ドル $S = 5000$.

330

$S = 5000$.

440

No additional constraints.

예제 입력 1

4 150
998244353 0
1000000007 1
1000000007 500000004
1000000007 642833014

예제 출력 1

0
1 1
1 2
3 1 19 2025

노트

In the first test case, the empty subset sums to $x = 0$ modulo $p = 998244353$.

In the second test case, $\frac{1}{1} \equiv 1 \pmod {1000000007}$.

In the third test case, $\frac{1}{2} \equiv 500000004 \pmod {1000000007}$.

In the fourth test case, $\frac{1}{1} + \frac{1}{19} + \frac{1}{2025} \equiv 642833014 \pmod {1000000007}$.

출처

University > MIT > M(IT)^2 > M(IT)^2 Winter 2025 Tournament > Advanced Round 1 5번

채점 및 기타 정보

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

출처

대학교 대회

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

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