#SP0000106. Số nguyên tố trong mọi đoạn con (Primes on Interval)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số nguyên tố trong mọi đoạn con (Primes on Interval)
Primes on Interval
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers with , find the smallest positive integer such that every interval of exactly consecutive integers wholly contained in contains at least primes. For each allowed start , where , the interval must contain at least primes. The length must satisfy . Output -1 if no such length exists.
An interval of exactly integers is contiguous. The condition must hold for every valid starting position, not just for one favorable interval.
Input
One line contains three integers , , and , in that order.
Output
Print the minimum valid length , or -1 if no valid length exists.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
6 13 1
Output
4
Explanation
The primes in are . The length- interval contains no prime, so length fails. Every length- interval contains a prime, including the critical windows , , and . Thus the minimum length is .