Compare Continued Fractions

시간 제한2초메모리 제한1024 MB

요약
길이가 최대 100,000인 두 유한 연분수가 주어질 때, 두 연분수가 나타내는 유리수의 대소를 비교해 <, =, > 중 하나를 출력한다.
난이도

보통10점 중 7점

유형
수학, 정수론, 구현, 완전 탐색
정답자
아직 제출이 없습니다

문제

In this problem, you have to compare two rational numbers represented by their continued fractions.

A finite continued fraction is a sequence \[a_0;a_1,a_2,…,a_n]\[a\_{0}; a\_{1}, a\_{2}, \ldots, a\_{n}]. The following restrictions are applied:

  • nn is a non-negative finite integer,
  • the elements a_0a\_{0}, a_1a\_{1}, a_2a\_{2}, …\ldots, a_na\_{n} are integers,
  • a_i>0a\_{i} > 0 for each i>0i > 0,
  • a_n>1a\_{n} > 1 if n>0n > 0.

These restrictions allow to establish a one-to-one correspondence between rational numbers and finite continued fractions: every rational number xx corresponds to the unique continued fraction \[a_0;a_1,a_2,…,a_n]\[a\_{0}; a\_{1}, a\_{2}, \ldots, a\_{n}] such that x=a_0+1a_1+1a_2+1⋱+1a_n.x = a\_{0} + \frac {1} {a\_{1} + \frac {1} {a\_{2} + \frac {1} {\ddots + \frac {1} {a\_{n}}}}}\text{.} Thus, the following notation is used: x=\[a_0;a_1,a_2,…,a_n]x = \[a\_{0}; a\_{1}, a\_{2}, \ldots, a\_{n}]. For example, 1725=0+12517=0+11+817=0+11+1178=0+11+12+18,\frac {17} {25} = 0 + \frac {1} {\frac {25} {17}} = 0 + \frac {1} {1 + \frac {8} {17}} = 0 + \frac {1} {1 + \frac {1} {\frac {17} {8}}} = \mathbf{0} + \frac {1} {\mathbf{1} + \frac {1} {\mathbf{2} + \frac {1} {\mathbf{8}}}}\text{,} so we write 1725=\[0;1,2,8]\frac {17} {25} = \[0; 1, 2, 8].

Given the continued fractions for two rational numbers xx and yy, find whether x<yx < y, x=yx = y, or x>yx > y.

입력

The input consists of two lines. The first line contains the continued fraction for the rational number xx. The second line contains the continued fraction for the rational number yy.

Each continued fraction is given as a sequence of integers separated by single spaces. First goes an integer nn, the length of the continued fraction (0≤n≤100,0000 \le n \le 100\\,000). It is followed by (n+1)(n + 1) integers which are the elements of the continued fraction: a_0a\_{0}, a_1a\_{1}, a_2a\_{2}, …\ldots, a_na\_{n} (∣a_i∣≤109|a\_{i}| \le 10^{9}). It is guaranteed that a_i>0a\_{i} > 0 for each i>0i > 0 and a_n>1a\_{n} > 1 if n>0n > 0.

출력

On the first line of output, print a single character: "<" if x<yx < y, "=" if x=yx = y, or ">" if x>yx > y.

예제3

  1. 예제 1

    입력
    1 0 3
    2 0 1 2
    
    예상 출력
    <
    
  2. 예제 2

    입력
    0 1
    0 1
    
    예상 출력
    =
    
  3. 예제 3

    입력
    1 -1 2
    0 -1
    
    예상 출력
    >