#P5438. Maximum Perfect Square Adjacent Pair Weight

    ID: 18670 Type: Default 1000ms 256MiB

Maximum Perfect Square Adjacent Pair Weight

Maximum Perfect Square Adjacent Pair Weight

You have lost your memory, and the Singer took it away. However, before leaving, the Singer told you that your memory contained a permutation of all integers from (l) to (r), and that this permutation has the maximum weight among all possible permutations.

The weight of a sequence is defined as the number of adjacent pairs ((a_i, a_{i+1})) such that the product (a_i \cdot a_{i+1}) is a perfect square, i.e., there exists an integer (k) satisfying (a_i \cdot a_{i+1} = k^2). It can be shown that (a_i \cdot a_{i+1}) is a perfect square if and only if the two numbers have the same square-free part.

Thus, to maximize the weight, one should group together numbers that have identical square-free parts. In any arrangement, if a group has (k) numbers sharing the same square-free part, they can contribute up to (k-1) to the weight. Since the permutation consists of every integer from (l) to (r) exactly once, the maximum weight equals ((r - l + 1) - G), where (G) is the number of distinct square-free parts among the numbers in ([l, r]).

Your task is to compute and output this maximum weight.

inputFormat

The input consists of a single line containing two integers (l) and (r) (with (l \le r)), separated by a space.

outputFormat

Output a single integer representing the maximum weight of a permutation of all integers from (l) to (r), i.e. [ \text{Maximum Weight} = (r - l + 1) - G, ] where (G) is the number of distinct square-free parts in the interval.

sample

1 10
3