Prime Distance


Submit solution

Points: 1
Time limit: 1.0s
Memory limit: 256M

Problem type
Allowed languages
C++, Python

Closest and Most Distant Prime Pairs Problem

Given two integers L and U, you need to find, within the closed interval [L, U], the pair of consecutive primes C1 and C2 (C1 < C2) that are closest (i.e., with the smallest difference C2 - C1). If multiple pairs have the same smallest difference, choose the first one.

Also, find the pair of consecutive primes D1 and D2 (D1 < D2) that are most distant (i.e., with the largest difference D2 - D1). If multiple pairs have the same largest difference, choose the first one.

Input Format
Each line contains two integers L and U. The difference between U and L does not exceed 106.

Output Format
For each L and U, output one line with the result.

The result should show the closest adjacent prime pair and the most distant adjacent prime pair in the format shown in the sample.

If there are no two primes in the interval [L, U], output:
There are no adjacent primes.

Data Range
1 ≤ L < U ≤ 231 - 1

Sample Input

2 17
14 17

Sample Output

2,3 are closest, 7,11 are most distant.
There are no adjacent primes.

Comments

There are no comments at the moment.