B - K-th Common Divisor Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

正整数 A, B が与えられます。

AB も割り切る正整数のうち、K 番目に大きいものを求めてください。

なお、与えられる入力では、AB も割り切る正整数のうち K 番目に大きいものが存在することが保証されます。

制約

  • 入力は全て整数である。
  • 1 \leq A, B \leq 100
  • AB も割り切る正整数のうち、K 番目に大きいものが存在する。
  • K \geq 1

入力

入力は以下の形式で標準入力から与えられる。

A B K

出力

AB も割り切る正整数のうち、K 番目に大きいものを出力せよ。


入力例 1

8 12 2

出力例 1

2

812 を割り切る正整数は 1, 2, 4 です。 この中で 2 番目に大きいものは 2 です。


入力例 2

100 50 4

出力例 2

5

入力例 3

1 1 1

出力例 3

1

Score : 200 points

Problem Statement

You are given positive integers A and B.

Find the K-th largest positive integer that divides both A and B.

The input guarantees that there exists such a number.

Constraints

  • All values in input are integers.
  • 1 \leq A, B \leq 100
  • The K-th largest positive integer that divides both A and B exists.
  • K \geq 1

Input

Input is given from Standard Input in the following format:

A B K

Output

Print the K-th largest positive integer that divides both A and B.


Sample Input 1

8 12 2

Sample Output 1

2

Three positive integers divides both 8 and 12: 1, 2 and 4. Among them, the second largest is 2.


Sample Input 2

100 50 4

Sample Output 2

5

Sample Input 3

1 1 1

Sample Output 3

1