P29551 [洛谷] [COCI2019-2020#1] Lutrija
普及
题目描述

Problem Background

After losing a bet on a lottery, Vedran accidentally tuned into the COCI channel. By completing the tasks given by COCI, he could avoid the expenses of attending the IOI2020 in Singapore.

Unfortunately, Vedran is old now, so you decide to help him.

Problem Description

Given two prime numbers \( A \) and \( B \). You need to construct a sequence that starts with \( A \) and ends with \( B \), where all elements are prime numbers, and the difference between any two adjacent elements is also a prime number.

Input Format

Two prime numbers \( A \) and \( B \) are provided as input.

Output Format

If it is impossible to complete the task, i.e., there is no sequence that meets the conditions (referred to as having a solution), output only -1.

Otherwise, output the number of elements in the sequence on the first line, and all the elements on the second line.

If there is a solution, your construction must satisfy one of the following conditions:

  • The number of elements in the sequence does not exceed 30.
  • None of the elements exceeds \( 10^{15} \).

If there are multiple solutions, output any one of them.

Sample Input and Output

Sample Input #1

13 11

Sample Output #1

2
13 11

Sample Input #2

37 11

Sample Output #2

-1

Sample Input #3

2 17

Sample Output #3

3
2 19 17

Notes

Data Size and Constraints

For 20% of the data, if there is a solution, there must be one solution where the number of elements does not exceed 3, and all elements do not exceed 1000.

For another 40% of the data, \( 2 \le A, B \le 1000 \).

For 100% of the data, \( 2 \le A, B \le 10^{14}, A \neq B \).

Notes

This problem is scored according to the original COCI settings, with a maximum score of 70.

Since each test case averages 2.5 points, half of the test cases are set to 2 points, and the other half are set to 3 points.

This problem uses a non-official Special Judge, and everyone is welcome to hack (either privately or by posting).

The problem is translated from COCI2019-2020 CONTEST #1 T2 Lutrija.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
13 11
样例输出
2 13 11