409534: GYM103625 H X Marks the Spot

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. X Marks the Spottime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Veos the treasure hunter has a quest for you! He has given you an arithmetic progression. Namely, it is denoted by the integers $$$a$$$ and $$$b$$$, with the arithmetic progression taking on the form $$$a, a + b, a + 2b, a + 3b, \dots$$$ and so on, with the first element in the progression being $$$a$$$.

Veos tells you that hidden within the arithmetic progression is a treasure and thus you must investigate a property of the arithmetic progression you've received. Notably, you want to find a contiguous subsequence of $$$k$$$ "clue"s in the arithmetic progression. Here, a "clue" is defined to be an element of the arithmetic sequence which is composite.

More formally, you would like to find an integer $$$x$$$ such that the numbers $$$a + xb, a + (x + 1)b, a + (x + 2)b, \dots, a + (x + k - 1)b$$$ are all composite.

Veos tells you that, "X marks the spot!", meaning that finding a suitable value for $$$x$$$ will lead you directly to the treasure! Are you up to the challenge?

Input

The input will consist of a single line containing the space-separated integers $$$a, b\ (3 \leq a, b \leq 100,000), k\ (1 \leq k \leq 1,000)$$$ in that order.

Output

The output should consist of a single integer, a suitable value of $$$x$$$. If there are multiple such values for $$$x$$$, output any of them.

ExamplesInput
4 3 1
Output
2
Input
3 5 2
Output
5
Note

A composite number is a natural number which can be factored into at least two smaller natural numbers. Some examples of composite numbers are $$$6$$$ ($$$2 \cdot 3 = 6$$$) and $$$100$$$ ($$$4 \cdot 25 = 100$$$).

A contiguous subsequence is a subsequence in which elements can be arranged in a consecutive fashion.

加入题单

算法标签: