#P1458. Irreducible Fractions
Irreducible Fractions
Irreducible Fractions
Given a natural number ( n ), find all irreducible fractions ( \frac{a}{b} ) satisfying ( 1 \leq b \leq n ) and ( 0 \leq \frac{a}{b} \leq 1 ). A fraction ( \frac{a}{b} ) is in simplest form if ( \gcd(a,b)=1 ) (note that for ( a=0 ), by convention ( \gcd(0,b)=b ), so the only valid zero fraction is ( \frac{0}{1} )). Output the fractions in increasing order of their numerical value.
For example, when ( n=5 ), the valid fractions are:
( \frac{0}{1},\ \frac{1}{5},\ \frac{1}{4},\ \frac{1}{3},\ \frac{2}{5},\ \frac{1}{2},\ \frac{3}{5},\ \frac{2}{3},\ \frac{3}{4},\ \frac{4}{5},\ \frac{1}{1} )
inputFormat
The input consists of a single natural number ( n ) (( n \geq 1 )).
outputFormat
Output all valid irreducible fractions in increasing order of their value. Each fraction should be printed on a separate line in the form ( \frac{a}{b} ) (i.e. as a/b).
sample
1
0/1
1/1
</p>