Prime Gap#5827

Prime Gap

5 seconds
64 megabytes
Easy

The sequence of n-1 consecutive composite numbers (positive integers that are not prime and not equal to ) lying between two successive prime numbers and p+n 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 .

Input

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.

Output

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.

Examples

Example 1

Loading
Loading