QOJ.ac

QOJ

Limite de temps : 6 s Limite de mémoire : 512 MB Points totaux : 100 Difficulté: [afficher] Hackable ✓

#9158. Fractions

Statistiques

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 $S$ is defined as a set of positive fractions satisfying the following five properties:

  1. $\frac{1}{2} \in S$;
  2. For $\frac{1}{2} < x < 2$, $x \notin S$;
  3. For all $x \in S$, $\frac{1}{x} \in S$;
  4. For all $x \in S$, $x + 2 \in S$;
  5. For all $x \in S$ and $x > 2$, $x - 2 \in S$.

It can be proven that the five properties above determine a unique 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 $\frac{i}{j}$ is a perfect positive fraction, i.e., $f(i, j) = 1$ if and only if $i$ and $j$ are coprime and $\frac{i}{j} \in S$, otherwise $f(i, j) = 0$.

Xiao C asks Xiao Y: Given $n$ and $m$, find the number of perfect positive fractions with numerator at most $n$ and denominator at most $m$, i.e., calculate $\sum_{i=1}^{n} \sum_{j=1}^{m} f(i, j)$.

Input

The first line contains two positive integers $n$ and $m$, representing the range of the numerator and the denominator, respectively.

Output

Output a single line containing a non-negative integer representing the corresponding answer.

Examples

Input 1

10 10

Output 1

16

Note 1

It can be proven that there are 16 perfect positive fractions with numerator and denominator both at most 10. The 8 fractions less than 1 are as follows: $\frac{1}{2}, \frac{1}{4}, \frac{1}{6}, \frac{1}{8}, \frac{1}{10}, \frac{2}{5}, \frac{2}{9}, \frac{4}{9}$. The 8 perfect positive fractions greater than 1 are the reciprocals of the 8 perfect positive fractions less than 1 listed above.

  • $\frac{2}{9}$ can be verified as a perfect positive fraction as follows: since $\frac{1}{2} \in S$, $\frac{1}{2} + 2 = \frac{5}{2} \in S$, $\frac{5}{2} + 2 = \frac{9}{2} \in S$, and $\frac{1}{9/2} = \frac{2}{9} \in S$, therefore $\frac{2}{9}$ is a perfect positive fraction.
  • $\frac{3}{7}$ can be verified as a perfect positive fraction as follows: assume $\frac{3}{7}$ is a perfect positive fraction, then $\frac{1}{3/7} = \frac{7}{3} \in S$, $\frac{7}{3} - 2 = \frac{1}{3} \in S$, $\frac{1}{1/3} = 3 \in S$, $3 - 2 = 1 \in S$, which contradicts the second property. Therefore, $\frac{3}{7}$ is not a perfect positive fraction.

Examples 2-4

See the files fraction/fraction2.in and fraction/fraction2.ans, fraction/fraction3.in and fraction/fraction3.ans, and fraction/fraction4.in and fraction/fraction4.ans in the contestant directory. These examples satisfy the constraints for test cases 4–6, 11–14, and 15–17, respectively.

Constraints

For all test data, it is guaranteed that $2 \le n, m \le 3 \times 10^7$.

Test Case ID $n \le$ $m \le$
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$

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.