eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Prime Gap

Prime Gap

The sequence of \textbf{n−1} consecutive composite numbers (positive integers that are not prime and not equal to \textbf{1}) lying between two successive prime numbers \textbf{p} and \textbf{p+n} is called a prime gap of length \textbf{n}. For example, (\textbf{24}, \textbf{25}, \textbf{26}, \textbf{27}, \textbf{28}) between \textbf{23} and \textbf{29} is a prime gap of length \textbf{6}. Your mission is to write a program to calculate, for a given positive integer \textbf{k}, the length of the prime gap that contains \textbf{k}. For convenience, the length is considered \textbf{0} in case no prime gap contains \textbf{k}. \InputFile The input is a sequence of lines each of which contains a single positive integer. Each positive integer is greater than \textbf{1} and less than or equal to the \textbf{100000}th prime number, which is \textbf{1299709}. The end of the input is indicated by a line containing a single zero. \OutputFile 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 \textbf{0} otherwise. No other characters should occur in the output.
Лимит времени 5 секунд
Лимит использования памяти 64 MiB
Входные данные #1
10
11
27
2
492170
0
Выходные данные #1
4
0
6
0
114
Источник ACM ICPC Japan Regional 2007