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

#GL0000301. Chỉ chia hết cho một số (Only one of two)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

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 NN, MM, and KK, where N≠MN\ne M.

A positive integer is called valid if it is divisible by exactly one of NN and MM: it must be divisible by either one, but not by both.

List all valid positive integers in increasing order. Find the KK-th smallest number in this infinite sequence.

Input

The only line contains three integers NN, MM, and KK: the two divisors and the required position.

Output

Print one integer: the KK-th smallest valid positive integer.

Subtasks

  • Subtask 1 (20 points): 1≤N,M≤301\le N,M\le30; N≠MN\ne M; 1≤K≤1001\le K\le100.
  • Subtask 2 (30 points): 1≤N,M≤1051\le N,M\le10^5; N≠MN\ne M; 1≤K≤1051\le K\le10^5.
  • Subtask 3 (50 points): 1≤N,M≤1081\le N,M\le10^8; N≠MN\ne M; 1≤K≤10101\le K\le10^{10}.

Examples

Example 1

Input

2 3 5

Output

9

Explanation

The first valid numbers are 2,3,4,8,92,3,4,8,9. We exclude 66 because it is divisible by both 22 and 33. The fifth number is 99.

Example 2

Input

1 2 3

Output

5

Explanation

Every positive integer is divisible by 11; even integers are also divisible by 22 and must be excluded. The valid numbers are 1,3,5,7,…1,3,5,7,\ldots, so the third one is 55.

Example 3

Input

100000000 99999999 10000000000

Output

500000002500000000

Explanation

Counting valid integers up to XX shows that X=500000002500000000X=500000002500000000 is the first position with at least 101010^{10} valid numbers. The answer requires a 64-bit integer.