QOJ.ac

QOJ

시간 제한: 2.0 s 메모리 제한: 256 MB 총점: 100

#18502. 比较连分数

통계

在本题中,你需要比较两个用连分数表示的有理数。

一个有限连分数是一个序列 $[a_0; a_1, a_2, \dots, a_n]$。它满足以下限制条件:

  • $n$ 是一个非负有限整数,
  • 元素 $a_0, a_1, a_2, \dots, a_n$ 是整数,
  • 对于每个 $i > 0$,有 $a_i > 0$,
  • 如果 $n > 0$,有 $a_n > 1$。

这些限制条件使得有理数与有限连分数之间建立了一一对应关系:每个有理数 $x$ 都对应唯一一个有限连分数 $[a_0; a_1, a_2, \dots, a_n]$,满足:

$$x = a_0 + \frac{1}{a_1 + \frac{1}{a_2 + \frac{1}{\dots + \frac{1}{a_n}}}}$$

因此,我们使用以下表示法:$x = [a_0; a_1, a_2, \dots, a_n]$。例如,

$$\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}}} = 0 + \frac{1}{1 + \frac{1}{2 + \frac{1}{8}}}$$

所以我们写成 $\frac{17}{25} = [0; 1, 2, 8]$。

给定两个有理数 $x$ 和 $y$ 的连分数表示,判断是 $x < y$、$x = y$ 还是 $x > y$。

输入格式

输入包含两行。第一行包含有理数 $x$ 的连分数表示。 第二行包含有理数 $y$ 的连分数表示。

每个连分数都以单空格分隔的整数序列形式给出。首先是一个整数 $n$,表示连分数的长度($0 \le n \le 100\,000$)。接着是 $(n + 1)$ 个整数,即连分数的元素:$a_0, a_1, a_2, \dots, a_n$($|a_i| \le 10^9$)。保证对于每个 $i > 0$ 都有 $a_i > 0$,且如果 $n > 0$ 则 $a_n > 1$。

输出格式

在输出的第一行打印一个字符:如果 $x < y$ 则输出 <,如果 $x = y$ 则输出 =,如果 $x > y$ 则输出 >

样例

输入样例 1

1 0 3
2 0 1 2

输出样例 1

<

说明 1

$x = 0 + \frac{1}{3} = \frac{1}{3}$,$y = 0 + \frac{1}{1 + \frac{1}{2}} = \frac{2}{3}$

输入样例 2

0 1
0 1

输出样例 2

=

说明 2

$x = 1$,$y = 1$

输入样例 3

1 -1 2
0 -1

输出样例 3

>

说明 3

$x = -1 + \frac{1}{2} = -\frac{1}{2}$,$y = -1$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.