program jihanki
  implicit none
  integer :: i, j, n
  integer :: a, b, k
  integer :: count
  integer, allocatable :: p(:)

  read(*,*)a,b,k
  n=min(a,b)
  allocate(p(n))

  i=n+1
  do while (i>0)
     i=i-1
     if (mod(a,i)==0 .and. mod(b,i)==0) then
        count=count+1
     end if
     if (count==k) then
        write(*,*)i
        exit
     end if
  end do
  
end program jihanki