program main
  implicit none
  integer :: A, B, K
  integer :: ndiv, ndiv_b
  integer,allocatable  :: divisor(:)
  integer,allocatable  :: divisor_b(:)
  integer :: i,j 
  read (*,*) A, B, K
  !
  ndiv = 0
  do i = 1, A
     if ( mod(A,i) == 0) then
        ndiv = ndiv + 1
     end if
  end do
  allocate( divisor(ndiv) )
  ndiv = 0
  do i  = 1, A
     if ( mod(A,i) == 0) then
        ndiv = ndiv + 1
        divisor(ndiv) = i
     end if
  end do
  !
  ndiv_b = 0
  do i = 1, B
     if ( mod(B,i) == 0) then
        ndiv_b = ndiv_b + 1
     end if
  end do
  allocate( divisor_b(ndiv_b) )
  ndiv_b = 0
  do i  = 1, B
     if ( mod(B,i) == 0) then
        ndiv_b = ndiv_b + 1
        divisor_b(ndiv_b) = i
     end if
  end do
  !
  if ( ndiv > ndiv_b ) then
     ndiv_b = 0
     do i = ndiv,1,-1
        if ( mod(B,divisor(i)) == 0)then
           ndiv_b = ndiv_b + 1
           if (ndiv_b == K ) then
              write(*,'(i0)') divisor(i)
              stop
           end if
        end if
     end do
  else
     ndiv = 0
     do i = ndiv_b,1,-1
        if ( mod(A,divisor_b(i)) == 0)then
           ndiv = ndiv + 1
           if (ndiv == K ) then
              write(*,'(i0)') divisor_b(i)
              stop
           end if
        end if
     end do
  end if
  deallocate( divisor, divisor_b )
end program main
