#P8058. [BalkanOI 2003] Farey 序列

    ID: 9152 远端评测题 1000ms 64MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2003二分数论素数判断,质数,筛法最大公约数 gcd莫比乌斯反演Stern-Brocot 树BalkanOI(巴尔干半岛)

[BalkanOI 2003] Farey 序列

Problem Description

Arrange all reduced proper fractions whose numerator and denominator are both n\leq n in increasing order. The resulting sequence is called the Farey sequence.

Find the kk-th smallest number in the Farey sequence for the given nn.

Input Format

One line with two integers n,kn, k.

Output Format

One line with two integers p,qp, q, representing the answer pq\frac{p}{q}.

5 6
3 5

Hint

For 100%100\% of the testdata, 2n4×1042 \leq n \leq 4 \times 10^4, and 1k1 \leq k \leq the number of fractions that satisfy the conditions.

Translated by ChatGPT 5