3828.Primes on Interval

Time Limit: 1s Memory Limit: 256MB

You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.

Consider positive integers a, a+1, ..., b (a \le b). You want to find the minimum integer l (1 \le l \le b-a+1) such that for any integer x (a \le x \le b-l+1) among l integers x, x+1, ..., x+l-1 there are at least k prime numbers.

Find and print the required minimum l. If no value l meets the described limitations, print -1.

Input Format(From the terminal/stdin)

A single line contains three space-separated integers a,b,k (1 \le a,b,k \le 106;a \le b).

Output Format(To the terminal/stdout)

In a single line print a single integer - the required minimum l. If there's no solution, print -1.

Sample Input 1

Copy
2 4 2
 · · \n

Sample Output 1

Copy
3
 \n

Sample Input 2

Copy
6 13 1
 ·  · \n

Sample Output 2

Copy
4
 \n

Sample Input 3

Copy
1 4 3
 · · \n

Sample Output 3

Copy
-1
  \n

Submit

请先 登录

© 2025 FAQs