#P10788. [NOI2024] 分数
[NOI2024] 分数
Background
Due to differences in the performance of judging machines, the original time limit was 6 s, and the Luogu time limit is 9 s.
Problem Description
Xiao Y and Xiao C are playing a game.
A positive fraction is defined as an irreducible fraction whose numerator and denominator are both positive integers.
A perfect positive fraction set is a set of positive fractions that satisfies the following five properties:
- ;
- For , ;
- For all , ;
- For all , ;
- For all and , .
It can be proven that the above five properties uniquely determine the perfect positive fraction set .
All positive fractions in the perfect positive fraction set are called perfect positive fractions. Let indicate whether is a perfect positive fraction. That is, if and only if and are coprime and ; otherwise .
Xiao C asks Xiao Y: given , find the number of perfect positive fractions whose numerator does not exceed and denominator does not exceed , that is, compute .
As time goes by, Xiao C and Xiao Y will meet again. Looking back, everyone has lived the life they wanted.
Input Format
The first line contains two positive integers and , representing the ranges of the numerator and denominator, respectively.
Output Format
Output one line containing a non-negative integer, representing the corresponding answer.
10 10
16
见 fraction2.in/ans
这个样例满足测试点 4-6 的约束条件
见 fraction3.in/ans
这个样例满足测试点 11-14 的约束条件
见 fraction4.in/ans
这个样例满足测试点 15-17 的约束条件
Hint
[Sample 1 Explanation]
It can be proven that there are perfect positive fractions with both numerator and denominator not exceeding . The that are less than are:
- $\dfrac{1}{2},\dfrac{1}{4},\dfrac{1}{6},\dfrac{1}{8},\dfrac{1}{10},\dfrac{2}{5},\dfrac{2}{9},\dfrac{4}{9}$.
The perfect positive fractions greater than are the reciprocals of the above perfect positive fractions less than .
- You can verify whether is a perfect positive fraction as follows: since , , , ;
- You can verify whether is a perfect positive fraction as follows: assume is a perfect positive fraction, then , , , , which contradicts the second property. Therefore, is not a perfect positive fraction.
[Constraints]
For all testdata, it is guaranteed that .
::cute-table{tuack}
| Test Point ID | ||
|---|---|---|
| ^ | ||
| ^ | ||
Translated by ChatGPT 5