Problem:
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

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramB a = new ProgramB();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            int sound = int.Parse(s[1]) / int.Parse(s[0]);

            if (sound < int.Parse(s[2]))
                Console.WriteLine(sound);
            else
                Console.WriteLine(int.Parse(s[2]));

        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int k = int.Parse(s[2]);

            int count = 0;

            for (int i = 100; i > 0; i--)
            {
                if (a % i == 0 && b % i == 0)
                    count++;

                if (count == k)
                {
                    Console.WriteLine(i);
                    return;
                }


            }
        }

        
    }

    class ProgramC
    {
        public void main()
        {

            //入力（decimal型だと桁精度が27桁ぐらいまである
            string[] s = Console.ReadLine().Split(' ');
            int x = int.Parse(s[0]);
            int n = int.Parse(s[1]);

            string[] a = Console.ReadLine().Split(' ');
            int[] dif = new int[100];
            for (int i = 0; i < n; i++)
                dif[int.Parse(a[i]) - 1]++;

            long ans1 = 0;
            long ans2 = 0;

            for(int i = x - 1;i<= 100;i++)
            {
                if (i == 100)
                {
                    ans1 = 101;
                    break;
                }

                if (dif[i] == 0)
                {
                    ans1 = i + 1;
                    break;
                }
            }

            for (int i = x - 1; i >= -1; i--)
            {
                if(i == -1)
                {
                    ans2 = 0;
                    break;
                }

                if (dif[i] == 0)
                {
                    ans2 = i + 1;
                    break;
                }
            }

            if(ans1 == ans2)
                Console.WriteLine(ans1);
            else if ((ans1 - x) < (x - ans2))
                Console.WriteLine(ans1);
            else
                Console.WriteLine(ans2);

        }
    }

    class ProgramD
    {
        public void main()
        {

            //入力
            long n = long.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');
            long[] a = new long[n];
            

            for (int i = 0; i < n; i++)
                a[i] = long.Parse(s[i]);

            //n=1のときは例外処理
            if(n == 1)
            {
                Console.WriteLine(1);
                return;
            }

            //ソートする
            Array.Sort(a);

            //1があれば例外処理
            if (a[0] == 1)
            {
                if (a[0] == a[1])
                    Console.WriteLine(0);
                else
                    Console.WriteLine(1);
                return;
            }

            //この整数は可能かどうかを見る
            long[] flag = new long[a[n - 1]];

            //同じ数があるか探す
            for (int i = 0; i < n - 1; i++)
            {
                if (a[i] == a[i + 1])
                {
                    flag[a[i] - 1] = 2;
                }
            }

            //それぞれの数で残るか検討
            for (int i = 0; i < n;i++)
            {
                //すでに数えたものは無視
                if (flag[a[i] - 1] == 1)
                    continue;

                //数えていないものはその倍数の可能性をつぶす
                long t = a[i];
                t += a[i];
                while(t <= a[n - 1])
                {
                    flag[t - 1] = 1;
                    t += a[i];
                }

            }

            //判定
            long ans = 0;
            for(int i = 0;i < n;i++)
            {
                //それぞれのAに対して0のものだけは成立する
                if (flag[a[i] - 1] == 0)
                    ans++;
            }

            //答え出力
            Console.WriteLine(ans);
        }
    }
}