#P7200. [COCI 2019/2020 #1] Lutrija

    ID: 7612 远端评测题 1000ms 500MiB 尝试: 32 已通过: 6 难度: 3 上传者: 标签>2019Special Judge深度优先搜索 DFS素数判断,质数,筛法COCI(克罗地亚)

[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 A,BA, B. You need to provide a sequence whose first and last elements are AA and BB, such that all elements are prime, and the difference between every two adjacent elements is also prime.

Input Format

Input two primes A,BA, 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 3030.
  • Every element is at most 101510^{15}.

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 20%20\% of the testdata, if there is a solution, then there must exist a solution where the number of elements is at most 33, and all elements are at most 10001000.

For another 40%40\% of the testdata, 2A,B10002 \le A, B \le 1000.

For 100%100\% of the testdata, 2A,B1014,AB2 \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 7070.

Since on average each test point is worth 2.52.5 points, half of the test points are set to 22 points, and the other half are set to 33 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