PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000251. Liệt kê các phân số hữu tỉ (Enumerating Rational Numbers)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Liệt kê các phân số hữu tỉ (Enumerating Rational Numbers)

Enumerating Rational Numbers

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Consider a sequence of rational numbers. For each denominator d=1,2,3,…d=1,2,3,\ldots in increasing order, inspect numerators p=0,1,…,dp=0,1,\ldots,d and append p/dp/d exactly when gcd⁡(p,d)=1\gcd(p,d)=1. The sequence starts 0/1,1/1,1/2,1/3,2/3,…0/1,1/1,1/2,1/3,2/3,\ldots. Given a one-based position kk, find the fraction at that position.

Input

One line contains the integer kk.

Output

Print the fraction at position kk in the format p/d, without spaces.

Subtasks

  • Subtask 1 (20 points): 1≤k≤10001\le k\le 1000.
  • Subtask 2 (30 points): 1≤k≤10000001\le k\le 1000000.
  • Subtask 3 (50 points): 1≤k≤121585989191\le k\le 12158598919.

Examples

Example 1

Input

1

Output

0/1

Explanation

The first fraction is 0/1.

Example 2

Input

2

Output

1/1

Explanation

The second fraction is 1/1.

Example 3

Input

3

Output

1/2

Explanation

Denominator 2 contributes fraction 1/2.

Example 4

Input

12158598919

Output

199999/200000

Explanation

The last fraction with denominator 200000 is 199999/200000.