题目描述
Problem Description
Xiao Y and Xiao C are playing a game.
A positive fraction is defined as a fraction where both the numerator and the denominator are positive integers and the fraction is in its simplest form.
A perfect positive fraction set $S$ is defined as a set of positive fractions that satisfies the following five properties:
- $\dfrac{1}{2} \in S$;
- For $\dfrac{1}{2} < x < 2$, $x \not \in S$;
- For all $x \in S$, $\dfrac{1}{x} \in S$;
- For all $x \in S$, $x + 2 \in S$;
- For all $x \in S$ where $x > 2$, $x - 2 \in S$;
It can be proven that these five properties uniquely determine the perfect positive fraction set $S$.
All positive fractions in the perfect positive fraction set $S$ are called perfect positive fractions. Let $f(i,j)$ denote whether $\dfrac{i}{j}$ is a perfect positive fraction, i.e., $f(i,j) = 1$ if and only if $i$ and $j$ are coprime and $\dfrac{i}{j} \in S$, otherwise $f(i,j) = 0$.
Xiao C asks Xiao Y: Given $n, m$, find the number of perfect positive fractions where the numerator does not exceed $n$ and the denominator does not exceed $m$, i.e., find $\sum_{i=1}^n \sum_{j=1}^m f(i,j)$.
Input Format
The first line of input contains two positive integers $n$ and $m$, representing the ranges of the numerator and the denominator, respectively.
Output Format
Output a single line containing a non-negative integer, representing the corresponding answer.
Sample Input and Output
Sample Input #1
10 10
Sample Output #1
16
Sample Input #2
See fraction2.in/ans
This sample satisfies the constraints of test points 4-6
Sample Output #2
Sample Input #3
See fraction3.in/ans
This sample satisfies the constraints of test points 11-14
Sample Output #3
Sample Input #4
See fraction4.in/ans
This sample satisfies the constraints of test points 15-17
Sample Output #4
Notes/Hints
[Sample 1 Explanation]
It can be proven that there are 16 perfect positive fractions with both numerator and denominator not exceeding 10, with 8 of them being less than 1 as follows:
- $\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 8 perfect positive fractions greater than 1 are the reciprocals of the above 8 fractions less than 1.
- Verification of $\dfrac{2}{9}$ being a perfect positive fraction: Since $\dfrac{1}{2} \in S$, $\dfrac{1}{2} + 2 = \dfrac{5}{2} \in S$, $\dfrac{5}{2} + 2 = \dfrac{9}{2} \in S$, $\dfrac{1}{\dfrac{9}{2}} = \dfrac{2}{9} \in S$;
- Verification of $\dfrac{3}{7}$ not being a perfect positive fraction: Assuming $\dfrac{3}{7}$ is a perfect positive fraction, then $\dfrac{1}{\dfrac{3}{7}} = \dfrac{7}{3} \in S$, $\dfrac{7}{3} - 2 = \dfrac{1}{3} \in S$, $\dfrac{1}{\dfrac{1}{3}} = 3 \in S$, $3 - 2 = 1 \in S$, which contradicts the second property, thus $\dfrac{3}{7}$ is not a perfect positive fraction.
[Data Range]
For all test data, it is guaranteed that $2 \leq n, m \leq 3 \times 10^7$.
| Test Point | $n \leq$ | $m \leq$ |
|---|---|---|
| 1-3 | $10^2$ | $10^2$ |
| 4-6 | $10^3$ | $10^3$ |
| 7-10 | $8,000$ | $8,000$ |
| 11-14 | $10^5$ | $10^5$ |
| 15-17 | $10^6$ | $10^6$ |
| 18 | $8 \times 10^6$ | $8 \times 10^6$ |
| 19 | $8 \times 10^6$ | $3 \times 10^7$ |
| 20 | $3 \times 10^7$ | $3 \times 10^7$ |
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分