#C7647. Good Sequence
Good Sequence
Good Sequence
You are given two integers n and m. Your task is to construct the lexicographically smallest good sequence of length n such that each element of the sequence is an integer between 1 and m (inclusive) and for every two consecutive elements a and b in the sequence, the condition
[ \gcd(a, b) > 1 ]
must hold. If no such sequence exists, output NO
.
Note: In this problem, the only valid construction (as defined by the sample tests) is to use the number 2 for the positions with even indices (starting at 0) and the number 4 for the positions with odd indices. This construction is only possible when m >= 2
for a single element sequence, and when m >= 4
for sequences with length greater than 1. Otherwise, output NO
.
inputFormat
The input consists of a single line containing two space-separated integers n
and m
, where n
is the length of the sequence and m
is the maximum allowable value for the elements in the sequence.
outputFormat
If a valid good sequence exists, output the sequence as space separated integers in one line. If no such sequence exists, output NO
.
3 4
2 4 2