PROGRAM ATCODER

implicit none
integer(16) :: n,i,a_sum,t_sum,j,s,s_a,s_t
integer(16),allocatable :: a(:),t(:)

read(*,*) n    !ここが入力欄
allocate(a(n), t(n))

do i = 1, n
  read(*,*) t(i), a(i)
end do

t_sum = 1
a_sum = 1
s = 0

do i = 1,n
  s_a = a_sum/a(i)
  s_t = t_sum/t(i)
  if(mod(a_sum,a(i)) /= 0)then
    s_a = s_a + 1  
  end if
  if(mod(t_sum,t(i)) /= 0)then
    s_t = s_t + 1  
  end if
  s = max(s_a,s_t)
  a_sum = a(i)*s
  t_sum = t(i)*s
end do

! ここに出力結果
write(*,'(i0)') t_sum+a_sum

contains
!!!!!! サブルーチンは↓

!!!!!!

END PROGRAM ATCODER
