P7200 [COCI 2019/2020 #1] Lutrija

Background

After Vedran lost a bet on the lottery, he accidentally opened the COCI channel. As long as he completes the tasks given by COCI, he can avoid paying the cost of traveling to IOI2020 on-site in Singapore. Unfortunately, Vedran has gotten old, so you decide to help him.

Description

Given two primes $A, B$. You need to provide a sequence whose first and last elements are $A$ and $B$, such that all elements are prime, and the difference between every two adjacent elements is also prime.

Input Format

Input two primes $A, B$.

Output Format

If the task is impossible, meaning there is no sequence that satisfies the conditions (called “a solution” below), output only `-1`. Otherwise, output the number of elements in the sequence on the first line, and output all elements on the second line. If there is a solution, your construction must satisfy at least one of the following: - The number of elements in the sequence is at most $30$. - Every element is at most $10^{15}$. If there are multiple solutions, output any one.

Explanation/Hint

#### Constraints For $20\%$ of the testdata, if there is a solution, then there must exist a solution where the number of elements is at most $3$, and all elements are at most $1000$. For another $40\%$ of the testdata, $2 \le A, B \le 1000$. For $100\%$ of the testdata, $2 \le A, B \le 10^{14}, A \neq B$. #### Notes **The score settings of this problem follow the original COCI problem, with a full score of $70$.** Since on average each test point is worth $2.5$ points, half of the test points are set to $2$ points, and the other half are set to $3$ points. This problem uses an unofficial [Special Judge](https://www.luogu.com.cn/paste/hrj05be5), and everyone is welcome to hack it (you can send a private message or post directly). **Translated from [COCI2019-2020](https://hsin.hr/coci/archive/2019_2020/) [CONTEST #1](https://hsin.hr/coci/archive/2019_2020/contest1_tasks.pdf) _T2 Lutrija_.** Translated by ChatGPT 5