#SP0000102. Khoảng cách các cặp nguyên tố kề nhau (Prime Distance)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 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 and , 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): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
2 17
Output
2,3 are closest, 7,11 are most distant.
Explanation
The primes are . Consecutive gaps are . The smallest gap is at . The largest gap is at and ; the earlier pair wins the tie.