K-th Common Divisor

AtCoder
IDabc120_b
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
8 12 2
Output #1
2

Three positive integers divides both $8$ and $12$: $1, 2$ and $4$. Among them, the second largest is $2$.
Input #2
100 50 4
Output #2
5
Input #3
1 1 1
Output #3
1
API Response (JSON)
{
  "problem": {
    "name": "K-th Common Divisor",
    "description": {
      "content": "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.",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc120_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given positive integers $A$ and $B$.\nFind the $K$\\-th largest positive integer that divides both $A$ and $B$.\nThe input guarantees that there exists such a number.\n\n## Constraints\n\n*   All val...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments