Inverse Knapsack
시간 제한3초메모리 제한256 MB
큰 소수 p와 목표 x가 주어질 때, 1부터 5000까지의 서로 다른 정수를 최대 S개 골라 역수의 합이 x와 p에 대해 합동이 되도록 만든다.
문제
For his number theory homework, Busy Beaver is given pairs of a large prime and an integer . For each pair, Busy Beaver needs to find a subset of of size at most whose sum is equal to modulo . Can you help him find such subsets?
A rational number is equal to modulo if .
입력
The first line contains two integers and (, ), indicating the number of testcases and the maximum size of the subset.
Each of the next lines contains two integers and (, ), where is prime.
출력
For each testcase, output one line indicating the answer. Start with some integer (), indicating the size of the subset, and then follow with distinct integers in increasing order ().
Your output should satisfy .
It can be proven that for all , satisfying the input constraints, such a subset always exists.
힌트
In the first test case, the empty subset sums to modulo .
In the second test case, .
In the third test case, .
In the fourth test case, .