#P7200. [COCI 2019/2020 #1] Lutrija
[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.
Problem Description
Given two primes . You need to provide a sequence whose first and last elements are and , such that all elements are prime, and the difference between every two adjacent elements is also prime.
Input Format
Input two primes .
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 .
- Every element is at most .
If there are multiple solutions, output any one.
13 11
2
13 11
37 11
-1
2 17
3
2 19 17
Hint
Constraints
For of the testdata, if there is a solution, then there must exist a solution where the number of elements is at most , and all elements are at most .
For another of the testdata, .
For of the testdata, .
Notes
The score settings of this problem follow the original COCI problem, with a full score of .
Since on average each test point is worth points, half of the test points are set to points, and the other half are set to points.
This problem uses an unofficial Special Judge, and everyone is welcome to hack it (you can send a private message or post directly).
Translated from COCI2019-2020 CONTEST #1 T2 Lutrija.
Translated by ChatGPT 5