#P7200. Prime Sequence with Prime Differences
Prime Sequence with Prime Differences
Prime Sequence with Prime Differences
Given two prime numbers \(A\) and \(B\), construct a sequence that starts with \(A\) and ends with \(B\). All elements in the sequence must be prime numbers and the absolute difference between any two consecutive elements must also be a prime number. If there exists at least one valid sequence, output any one of them; otherwise, output Impossible
.
Note: The sequence is not required to be the shortest possible one. All primes used (including intermediate ones) are chosen from a fixed range (2 up to 1000) to ensure feasibility.
inputFormat
The input consists of a single line containing two space-separated integers \(A\) and \(B\), both of which are prime numbers.
outputFormat
If a valid sequence exists, output the sequence in one line with each number separated by a single space. If no valid sequence exists under the given constraints, output Impossible
.
sample
3 5
3 5