#C5321. Lexicographically Smallest Prime Sequence
Lexicographically Smallest Prime Sequence
Lexicographically Smallest Prime Sequence
You are given several test cases. In each test case, you are given two integers N and M. Your task is to construct a sequence of length N which contains exactly M prime numbers. The sequence should be formed by taking the first M prime numbers followed by N-M copies of the number 1. If it is impossible to create such a sequence (i.e. when M > N), output SEQUENCE IMPOSSIBLE
.
Note: The sequence is to be printed as a space-separated string on a single line for each test case.
Examples:
Input: 3 2 1 4 2 5 6</p>Output: 2 1 2 3 1 1 SEQUENCE IMPOSSIBLE
Another example:
Input: 3 10 0 10 1 10 10</p>Output: 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 3 5 7 11 13 17 19 23 29
inputFormat
The first line of input contains a single integer T representing the number of test cases. Each of the following T lines contains two space-separated integers N and M, where N is the length of the sequence and M is the required number of prime numbers in the sequence.
outputFormat
For each test case, output a single line containing the lexicographically smallest sequence that satisfies the condition. If no valid sequence exists, output SEQUENCE IMPOSSIBLE
.
3
2 1
4 2
5 6
2 1
2 3 1 1
SEQUENCE IMPOSSIBLE
</p>