3205. Prime Gap

Medium循环数组基本算法

时间限制:8000 ms

内存限制:256 MiB

题面

The sequence of n1n - 1 consecutive composite numbers (positive integers that are not prime and not equal to 11) lying between two successive prime numbers pp and p+np + n is called a prime gap of length nn. For example, (24,25,26,27,28)(24, 25, 26, 27, 28) between 2323 and 2929 is a prime gap of length 66.

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

输入格式

The input is a sequence of lines each of which contains a single positive integer. Each positive integer is greater than 11 and less than or equal to the 100000100000-th prime number, which is 12997091299709. 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 00 otherwise. No other characters should occur in the output.

样例

输入

10
11
27
2
492170
0

输出

4
0
6
0
114