#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 SS is a set of positive fractions that satisfies the following five properties:

  • 12S\dfrac{1}{2}\in S;
  • For 12<x<2\dfrac{1}{2}<x<2, x∉Sx\not \in S;
  • For all xSx\in S, 1xS\dfrac{1}{x}\in S;
  • For all xSx\in S, x+2Sx+2 \in S;
  • For all xSx\in S and x>2x>2, x2Sx-2 \in S.

It can be proven that the above five properties uniquely determine the perfect positive fraction set SS.

All positive fractions in the perfect positive fraction set SS are called perfect positive fractions. Let f(i,j)f(i,j) indicate whether ij\dfrac{i}{j} is a perfect positive fraction. That is, f(i,j)=1f(i,j)=1 if and only if ii and jj are coprime and ijS\dfrac{i}{j} \in S; otherwise f(i,j)=0f(i,j)=0.

Xiao C asks Xiao Y: given n,mn,m, find the number of perfect positive fractions whose numerator does not exceed nn and denominator does not exceed mm, that is, compute i=1nj=1mf(i,j)\sum_{i=1}^n \sum_{j=1}^m f(i,j).

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 nn and mm, 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 1616 perfect positive fractions with both numerator and denominator not exceeding 1010. The 88 that are less than 11 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 88 perfect positive fractions greater than 11 are the reciprocals of the above 88 perfect positive fractions less than 11.

  • You can verify whether 29\dfrac{2}{9} is a perfect positive fraction as follows: since 12S\dfrac{1}{2}\in S, 12+2=52S\dfrac{1}{2}+2=\dfrac{5}{2}\in S, 52+2=92S\dfrac{5}{2}+2=\dfrac{9}{2}\in S, 192=29S\dfrac{1}{\dfrac{9}{2}}=\dfrac{2}{9}\in S;
  • You can verify whether 37\dfrac{3}{7} is a perfect positive fraction as follows: assume 37\dfrac{3}{7} is a perfect positive fraction, then 137=73S\dfrac{1}{\dfrac{3}{7}}=\dfrac{7}{3}\in S, 732=13S\dfrac{7}{3}-2=\dfrac{1}{3}\in S, 113=3S\dfrac{1}{\dfrac{1}{3}}=3\in S, 32=1S3-2=1\in S, which contradicts the second property. Therefore, 37\dfrac{3}{7} is not a perfect positive fraction.

[Constraints]

For all testdata, it is guaranteed that 2n,m3×1072\leq n,m\leq 3\times 10^7.

::cute-table{tuack}

Test Point ID nn\leq mm\leq
131\sim 3 10210^2
464\sim 6 10310^3
7107\sim 10 80008\,000
111411\sim 14 10510^5
151715\sim 17 10610^6
1818 8×1068\times 10^6
1919 ^ 3×1073\times 10^7
2020 3×1073\times 10^7 ^

Translated by ChatGPT 5