#GL0000301. Chỉ chia hết cho một số (Only one of two)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chỉ chia hết cho một số (Only one of two)
Only one of two
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
You are given positive integers , , and , where .
A positive integer is called valid if it is divisible by exactly one of and : it must be divisible by either one, but not by both.
List all valid positive integers in increasing order. Find the -th smallest number in this infinite sequence.
Input
The only line contains three integers , , and : the two divisors and the required position.
Output
Print one integer: the -th smallest valid positive integer.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Example 1
Input
2 3 5
Output
9
Explanation
The first valid numbers are . We exclude because it is divisible by both and . The fifth number is .
Example 2
Input
1 2 3
Output
5
Explanation
Every positive integer is divisible by ; even integers are also divisible by and must be excluded. The valid numbers are , so the third one is .
Example 3
Input
100000000 99999999 10000000000
Output
500000002500000000
Explanation
Counting valid integers up to shows that is the first position with at least valid numbers. The answer requires a 64-bit integer.