QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 256 MB Points totaux : 100

#5624. 法里数列之和

Statistiques

给定一个正整数 $N$,所有满足 $0 < a \le b$,$1 < b \le N$,且 $a$ 与 $b$ 互质的分数 $a / b$ 按升序排列组成的序列,被称为 $N$ 阶 Farey 序列。

例如,6 阶 Farey 序列为: $0/1, 1/6, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 5/6, 1/1$

如果 $N$ 阶 Farey 序列的分母为: $b[1], b[2], \dots, b[K]$

那么 $N$ 阶 Farey 和为从 $i = 1$ 到 $K-1$ 的 $b[i] / b[i+1]$ 之和。

例如,6 阶 Farey 和为: $1/6 + 6/5 + 5/4 + 4/3 + 3/5 + 5/2 + 2/5 + 5/3 + 3/4 + 4/5 + 5/6 + 6/1 = 35/2$

编写一个程序来计算 $N$ 阶 Farey 和(输入)。

输入格式

输入的第一行包含一个整数 $P$ ($1 \le P \le 10000$),表示随后数据集的数量。每个数据集应被独立处理。

每个数据集由单行输入组成。它包含数据集编号 $K$,后跟需要计算 Farey 和的阶数 $N$ ($2 \le N \le 10000$)。

输出格式

对于每个数据集,输出一行。输出行包含数据集编号 $K$,后跟一个空格,以及作为最简分数形式的 Farey 和。如果分母为 1,则仅输出分子。

样例

样例输入 1

4
1 6
2 15
3 57
4 9999

样例输出 1

1 35/2
2 215/2
3 2999/2
4 91180457/2

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.