# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
$aa = inputs[0][0]
$bb = inputs[0][1]
$kk = inputs[0][2]

if $debugFlag
  p $aa
  p $bb
  p $kk  
end

if $aa > $bb
  min = $bb
else
  min = $aa
end

comd = []
min.times do |i|
  comd << (i + 1) if $aa % (i + 1) == 0 and $bb % (i + 1) == 0
end

if $debugFlag
  print "comd: "
  p comd
end

puts comd.reverse[$kk-1]
