PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000194. Dãy nguyên tố cách đều (Determinate Prime)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Dãy nguyên tố cách đều (Determinate Prime)

Determinate Prime

Phuoc Hung OJ ID: PRIME000199
Original source: UVa 10650

Problem statement

A run of at least three consecutive primes is equally spaced if all neighboring differences are equal. Print all maximal runs fully contained in the given interval. Do not print proper subruns of a longer run.

Input

Two non-negative integers x,yx,y.

Output

Print each maximal run of at least three consecutive primes in arithmetic progression, provided the entire run lies in [min⁡(x,y),max⁡(x,y)][\min(x,y),\max(x,y)]. One run per line; print nothing if none.

Subtasks

  • Subtask 1 (20 points): 0≤x y≤5000\le x\,y\le 500.
  • Subtask 2 (30 points): 501≤x y≤10 000501\le x\,y\le 10\,000.
  • Subtask 3 (50 points): 10 001≤x y≤32 00010\,001\le x\,y\le 32\,000.

Both interval endpoints are at most 32 00032\,000.

Example

Input

1 100

Output

3 5 7
47 53 59

Explanation: The runs 3,5,73,5,7 and 47,53,5947,53,59 have constant gaps 22 and 66, respectively; both are maximal and fully inside the interval.