#P1458. [USACO2.1] 顺序的分数 Ordered Fractions

[USACO2.1] 顺序的分数 Ordered Fractions

Description

Input a natural number nn. For a reduced fraction a/ba/b (a fraction whose numerator and denominator are coprime) that satisfies 1bn,0a/b11 \le b \le n, 0 \le a/b \le 1, find all fractions meeting the conditions.

Here is an example. When n=5n=5, all solutions are:

$$\frac01,\frac15,\frac14,\frac13,\frac25,\frac12,\frac35,\frac23,\frac34 ,\frac45,\frac11$$

Given a natural number nn, write a program to output all solutions in increasing order of their values.

Note:

  1. The greatest common divisor of 00 and any natural number is that natural number.
  2. “Coprime” means the greatest common divisor of the two natural numbers equals 11.

Input Format

A single line containing a natural number nn.

Output Format

Each fraction occupies one line, in increasing order.

5

0/1
1/5
1/4
1/3
2/5
1/2
3/5
2/3
3/4
4/5
1/1

Hint

Constraints
For 100%100\% of the testdata, 1n1601 \le n \le 160.

USACO 2.1

Translation from NOCOW.

Translated by ChatGPT 5