#P16878. [GKS 2022 #C] Range Partition

    ID: 17124 Type: RemoteJudge 1000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 5 Uploaded By: Tags>数学贪心2022Special Judge构造Google Kick Start

[GKS 2022 #C] Range Partition

题目描述

Alan and Barbara suddenly felt like playing with numbers. Alan chooses a non-empty subset from the set of first NN positive integers (1,2,…,N)(1, 2, \ldots, N). Barbara takes the rest of the numbers (if any) from the set. And then they both calculate the sum of the elements in their respective sets.

Alan believes in a magic ratio, which is X:YX : Y. Hence, Alan wants to choose the subset in such a way that the ratio between the sum of Alan's subset and the sum of Barbara's subset is exactly X:YX : Y.

Can you help Alan to choose a subset that can achieve the desired ratio?

输入格式

The first line of the input gives the number of test cases, TT. TT test cases follow.

Each test case has a single line containing 33 integers, NN, XX and YY, as described above.

输出格式

For each test case, output the first line containing Case #xx: yy, where xx is the test case number (starting from 11) and yy is POSSIBLE, if Alan can choose such a non-empty subset, and IMPOSSIBLE otherwise.

If you print POSSIBLE, then output two more lines for that test case.

In the second line, print a single integer, which denotes the size of Alan's subset.

In the third line, print the integers present in Alan's subset.

If there are multiple solutions, you can print any of them.

3
3 1 2
3 1 1
3 1 3
Case #1: POSSIBLE
1
2
Case #2: POSSIBLE
2
1 2
Case #3: IMPOSSIBLE

提示

In the first test case, Alan chooses {2}\{2\}. Then Barbara gets {1,3}\{1,3\}, which sums up to 1+3=41 + 3 = 4. So the ratio is 2:42 : 4, which is equivalent to 1:21 : 2.

In the second test case, Alan chooses {1,2}\{1,2\}, which sums up to 1+2=31 + 2 = 3. And Barbara gets {3}\{3\}. So the ratio is 3:33 : 3, which is equivalent to 1:11 : 1.

In the third test case, it is not possible for Alan to choose a subset that satisfies the condition.

Limits

1≤T≤1001 \le T \le 100.

1≤X≤1081 \le X \le 10^8.

1≤Y≤1081 \le Y \le 10^8.

gcd⁡(X,Y)=1\gcd(X, Y) = 1, where gcd is Greatest common divisor.

Test Set 11

1≤N≤151 \le N \le 15.

Test Set 22

1≤N≤50001 \le N \le 5000.