fun main(args: Array<String>) {
    val (A, B, K) = readLine()!!.split(" ").map(String::toInt)
    val list = mutableListOf<Int>()
    for (i in Math.min(A, B) downTo 1) {
        if (A % i == 0 && B % i == 0) {
            list.add(i)
            if (list.size == K) {
                println(list[K-1])
                return
            }
        }
    }
}