3205. Prime Gap

单点时限: 8.0 sec

内存限制: 256 MB

The sequence of consecutive composite numbers (positive integers that are not prime and not equal to ) lying between two successive prime numbers and is called a prime gap of length . For example, between and is a prime gap of length .

Your mission is to write a program to calculate, for a given positive integer , the length of the prime gap that contains . For convenience, the length is considered in case no prime gap contains .

输入格式

The input is a sequence of lines each of which contains a single positive integer. Each positive integer is greater than and less than or equal to the -th prime number, which is . The end of the input is indicated by a line containing a single zero.

输出格式

The output should be composed of lines each of which contains a single non-negative integer. It is the length of the prime gap that contains the corresponding positive integer in the input if it is a composite number, or otherwise. No other characters should occur in the output.

样例

Input
10
11
27
2
492170
0
Output
4
0
6
0
114

15 人解决,15 人已尝试。

17 份提交通过,共有 21 份提交。

3.0 EMB 奖励。

创建: 2 年,9 月前.

修改: 2 年,3 月前.

最后提交: 7 月,3 周前.

来源: Tokyo 2007

题目标签