#P1014. Cantor's Rational Enumeration

    ID: 12128 Type: Default 1000ms 256MiB

Cantor's Rational Enumeration

Cantor's Rational Enumeration

Georg Cantor proved that the set of rational numbers is countable by demonstrating an enumeration using a table where the element at row i and column j is the fraction \(\frac{i}{j}\). The enumeration is done in a "Z"-shaped order. The first term is \(1/1\), then \(1/2\), \(2/1\), \(3/1\), \(2/2\), \(1/3\), and so on.

For a given positive integer \(n\), your task is to determine the \(n\)th term in this enumeration. The enumeration can be described as follows:

  • Consider diagonals in the table. The first diagonal (with one element) is formed by the cell \((1,1)\).
  • The second diagonal (with two elements) consists of \((1,2)\) and \((2,1)\). Note that this diagonal is traversed from top to bottom.
  • The third diagonal (with three elements) consists of \((1,3)\), \((2,2)\), and \((3,1)\), but this time the traversal order is reversed (from bottom to top).
  • The order of traversal alternates with each diagonal.

Formally, if we denote the diagonal by an integer \(d\) (starting from 1 for the first diagonal), and let \(k\) be the position of \(n\) within the diagonal, then:

  • If \(d\) is odd, the \(n\)th fraction is \(\frac{d - k + 1}{k}\).
  • If \(d\) is even, the fraction is \(\frac{k}{d - k + 1}\).

Note: The fractions are not reduced to their simplest form; print them as they appear in the table.

inputFormat

A single positive integer (n) representing the position in Cantor's enumeration.\n\nConstraints: (1 \le n \le 10^7).

outputFormat

Print the fraction in the form "numerator/denominator" that is at the (n)th position in the enumeration.

sample

1
1/1