#P1458. [USACO2.1] 顺序的分数 Ordered Fractions
[USACO2.1] 顺序的分数 Ordered Fractions
Description
Input a natural number . For a reduced fraction (a fraction whose numerator and denominator are coprime) that satisfies , find all fractions meeting the conditions.
Here is an example. When , all solutions are:
$$\frac01,\frac15,\frac14,\frac13,\frac25,\frac12,\frac35,\frac23,\frac34 ,\frac45,\frac11$$Given a natural number , write a program to output all solutions in increasing order of their values.
Note:
- The greatest common divisor of and any natural number is that natural number.
- “Coprime” means the greatest common divisor of the two natural numbers equals .
Input Format
A single line containing a natural number .
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 of the testdata, .
USACO 2.1
Translation from NOCOW.
Translated by ChatGPT 5
京公网安备 11011102002149号