#B4308. Sum of Möbius Function

    ID: 11964 Type: Default 1000ms 256MiB

Sum of Möbius Function

Sum of Möbius Function

Given two positive integers m and n, compute the sum of the Möbius function values for all integers between m and n (inclusive).

Definitions:

  • Divisor: A divisor (or factor) of an integer a is an integer b such that when a is divided by b the quotient is an integer and the remainder is 0. For example, 1, 2, 3, and 6 are divisors of 6.
  • Prime: A prime number is a natural number greater than 1 that has no divisors other than 1 and itself. For example, 2, 3, and 5 are primes, whereas 4, 6, and 8 are not.
  • Perfect Square: A number that can be expressed as the square of an integer. For example, 4 (22), 9 (32), and 16 (42) are perfect squares.
  • Möbius Function: The Möbius function \(\mu(n)\) is defined as follows:
    1. If \(n = 1\), then \(\mu(n) = 1\);
    2. If n has a squared prime factor (i.e. a divisor that is a perfect square greater than 1), then \(\mu(n) = 0\);
    3. If n is a product of k distinct primes, that is \(n = P_1 \times P_2 \times \cdots \times P_k\), then \(\mu(n) = (-1)^k\).

For example:

  • 8 has divisors 1, 2, 4, 8. Since 4 is a perfect square greater than 1, \(\mu(8) = 0\).
  • 15 has divisors 1, 3, 5, 15, and since 15 = 3 \(\times\) 5 (two distinct primes), \(\mu(15) = (-1)^2 = 1\.
  • 30 has divisors 1, 2, 3, 5, 6, 10, 15, 30, and since 30 = 2 \(\times\) 3 \(\times\) 5 (three distinct primes), \(\mu(30) = (-1)^3 = -1\.

Your task is to compute the sum:

\[ \sum_{i=m}^{n} \mu(i) \]

inputFormat

The input consists of a single line containing two positive integers m and n, separated by a space.

outputFormat

Output a single integer, which is the sum of \(\mu(i)\) for all integers i in the range [m, n].

sample

1 1
1