I also like thisone, $\mathcal{O}(N \ln N)$ additions being not so different of to $\mathcal{O}(N \ln \ln N)$ multiplications :
% N(1+ln N) additions/affectations. an array of 2 bits elements would be enough !
% matlab
function mu = computeMu(N)
mu = -oneszeros(1,N); mu(1) = 1;
% Will compute the Dirichlet inverse of any sequence starting with 1
for n = 21:N
mu(n+n:n:end) = mu(n+n:n:end) - mu(n);
end
end
// C++/java/C#
char[] computeMu(int N) {
char[] mu = new char[N+1];
mu[0] = 0; mu[1] = 1; for (int n = 2; n <= N; n++) mu[n] = -1;
for (int n = 2; n <= N; n++) {
if (mu[n]) {
for (int m = n+n; m <= N; m += n) mu[m] -= mu[n];
}
}
return mu;
}
I'll leave you as an exercice to prove that it effectly computes $\mu(n)$
$$ \left(\sum_n \mu_n n^0 \right) \left(\sum_m m^0 \right) = \sum_n n^0 \sum_{d | n} \mu_d$$