Compute the Mertens function Given a positive integer n, compute the value of the Mertens function M(n) where



and μ(k) is the Möbius function where μ(k) = 1 if k has an even number of distinct prime factors, -1 if k has an odd number of distinct prime factors, and 0 if the prime factors are not distinct.


This is code-golf so create the shortest code for a function or program that computes the Mertens function for an input integer n > 0.
This is the OEIS sequence A002321.


Test Cases

n M(n)
1 1
2 0
3 -1
4 -1
5 -2
6 -1
7 -2
8 -2
9 -2
10 -1
117 -5
5525 5
7044 -25
8888 4
10000 -23
Mathematica, 22 20 bytes

Thanks to @miles for saving 2 bytes.

Tr@*MoebiusMu@*Range


Explanation

Range


Generate a list from 1 to input.

MoebiusMu


Find MoebiusMu of each number

Tr


Sum the result.