program main
implicit none
integer :: a, b, k
integer :: i, j

read(*,*) a, b, k

j = 0
do i = b, 1, -1
   if(mod(a,i) == 0 .and. mod(b,i) == 0 ) then
      j = j + 1
   end if
   if(j == k) then
      write(*,'(i0)') i
      stop
   end if
end do

end program main
