PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000106. Số nguyên tố trong mọi đoạn con (Primes on Interval)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 a,b,ka,b,k with a≤ba\le b, find the smallest positive integer ℓ\ell such that every interval of exactly ℓ\ell consecutive integers wholly contained in [a,b][a,b] contains at least kk primes. For each allowed start xx, where a≤x≤b−ℓ+1a\le x\le b-\ell+1, the interval [x,x+ℓ−1][x,x+\ell-1] must contain at least kk primes. The length must satisfy 1≤ℓ≤b−a+11\le\ell\le b-a+1. Output -1 if no such length exists.

An interval of exactly ℓ\ell integers is contiguous. The condition must hold for every valid starting position, not just for one favorable interval.

Input

One line contains three integers aa, bb, and kk, in that order.

Output

Print the minimum valid length ℓ\ell, or -1 if no valid length exists.

Subtasks

  • Subtask 1 (20 points): 1≤a≤b≤2001\le a\le b\le 200; 1≤k≤101\le k\le 10.
  • Subtask 2 (30 points): 1≤a≤b≤200001\le a\le b\le 20000; 1≤k≤1001\le k\le 100.
  • Subtask 3 (50 points): 1≤a≤b≤10000001\le a\le b\le 1000000; 1≤k≤10000001\le k\le 1000000.

Examples

Input

6 13 1

Output

4

Explanation

The primes in [6,13][6,13] are 7,11,137,11,13. The length-33 interval [8,10][8,10] contains no prime, so length 33 fails. Every length-44 interval contains a prime, including the critical windows [8,11][8,11], [9,12][9,12], and [10,13][10,13]. Thus the minimum length is 44.