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

#SP0000102. Khoảng cách các cặp nguyên tố kề nhau (Prime Distance)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Khoảng cách các cặp nguyên tố kề nhau (Prime Distance)

Prime Distance

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

List the primes in the closed interval [L,U][L,U] in increasing order. Two consecutive numbers in this list form an adjacent prime pair. Find the adjacent pair with the minimum difference and the adjacent pair with the maximum difference. For ties, select the pair that appears first in increasing order. If the interval contains fewer than two primes, print the prescribed no-pair message.

If multiple pairs have an equal gap, select only the pair that appears earliest in the increasing list.

Input

One line contains two integers LL and UU, the inclusive left and right endpoints of the interval.

Output

If at least two primes exist, print exactly C1,C2 are closest, D1,D2 are most distant. with the corresponding numbers and no spaces after commas. Otherwise print There are no adjacent primes.

Subtasks

  • Subtask 1 (20 points): 1≤L<U≤100001\le L< U\le 10000; U−L≤500U-L\le 500.
  • Subtask 2 (30 points): 1≤L<U≤100000001\le L< U\le 10000000; U−L≤100000U-L\le 100000.
  • Subtask 3 (50 points): 1≤L<U≤21474836471\le L< U\le 2147483647; U−L≤1000000U-L\le 1000000.

Examples

Input

2 17

Output

2,3 are closest, 7,11 are most distant.

Explanation

The primes are 2,3,5,7,11,13,172,3,5,7,11,13,17. Consecutive gaps are 1,2,2,4,2,41,2,2,4,2,4. The smallest gap is 11 at (2,3)(2,3). The largest gap is 44 at (7,11)(7,11) and (13,17)(13,17); the earlier pair (7,11)(7,11) wins the tie.