Minho takes a discrete mathematics course. One day the professor proved that the positive rational numbers are countable and then assigned homework.
The positive rationals are listed by the following rule. Collect the fractions whose numerator and denominator have the same sum into one group, and number the groups starting from the smallest sum. The group with sum s holds s−1 fractions, and inside the group they are written from the largest numerator down: 1s−1,2s−2,…,s−11.
The listing therefore runs 11,12,21,13,22,31,14,…. The first rational is 11, the second is 12, the third is 21, the fourth is 13, and the fifth is 22.
Fractions of equal value such as 11,22,33 count as separate terms. Nothing is reduced.
Minho does not want to do the homework by hand, so he writes a program instead. Find the N-th rational number.