import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLine >>= print . solve

solve :: [Int] -> Int
solve [a, b, k] = head . drop (k - 1) $ sortBy (flip compare) [i | i <- [1..x], x `mod` i == 0, y `mod` i == 0]
    where
        [x, y] = sort [a, b]

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine