#P5438. 【XR-2】记忆

    ID: 4379 远端评测题 1200ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>O2优化素数判断,质数,筛法容斥

【XR-2】记忆

Description

Your memory was taken away by the Singer.

Before leaving, the Singer told you that there is a sequence in your memory, and this sequence is a permutation of all integers xx with lxrl \le x \le r.

After thinking for a moment, the Singer decided to tell you a bit more:

If we define the weight of a sequence as the number of adjacent pairs whose product is a perfect square, then the sequence in your memory is the permutation with the maximum weight among all permutations formed by the integers xx with lxrl \le x \le r.

The Singer wants you to tell him the weight of the sequence in your memory. Only then will he return your memory to you.

Input Format

One line containing two positive integers l,rl, r.

Output Format

One line containing one integer, which is the answer.

2 10

2

Hint

[Sample 11 Explanation]

One permutation with weight 22 is {8,2,4,9,3,10,7,5,6}\{8,2,4,9,3,10,7,5,6\}. In it, 8×2=168 \times 2 = 16 and 4×9=364 \times 9 = 36 are perfect squares. This is also the permutation with the maximum weight among all permutations formed by the integers xx with 2x102 \le x \le 10.

[Constraints]

This problem uses bundled tests.

Subtask 1 (3 points): r10r \le 10.
Subtask 2 (7 points): r100r \le 100.
Subtask 3 (15 points): r100000r \le 100000.
Subtask 4 (11 points): l=1l = 1.
Subtask 5 (8 points): l10l \le 10.
Subtask 6 (19 points): l1000000l \le 1000000.
Subtask 7 (37 points): no special restrictions.

For 100%100\% of the testdata, 1lr10141 \le l \le r \le 10^{14}.

Translated by ChatGPT 5