user
The classical **Möbius function: μ(n)** is an important multiplicative function in number theory and combinatorics.

There are several ways to implement a Möbius function.

A fairly straightforward method is to find the prime factors of a positive integer **n**, then define **μ(n)** based on the sum of the primitive factors. It has the values **{−1, 0, 1}** depending on the factorization of **n**:

:   * **μ(1)** is defined to be **1**.

:   * **μ(n) = 1** if **n** is a square-free positive integer with an **even** number of prime factors.

:   * **μ(n) = −1** if **n** is a square-free positive integer with an **odd** number of prime factors.

:   * **μ(n) = 0** if **n** has a **squared** prime factor.

Task
:   * Write a routine (function, procedure, whatever) **μ(n)** to find the Möbius number for a positive integer **n**.

:   * Use that routine to find and display here, on this page, at least the first 99 terms in a grid layout. (Not just one long line or column of numbers.)

See also
:   * Wikipedia: Möbius function

Related Tasks
:   * Mertens function
assistant
(formerly Perl 6)

**Works with**: Rakudo version 2022.12

Möbius number is not defined for n == 0. Raku arrays are indexed from 0 so store a blank value at position zero to keep n and μ(n) aligned.

```
use Prime::Factor;

sub μ (Int \n) {
    return 0 if n %% (4|9|25|49|121);
    my @p = prime-factors(n);
    +@p == +@p.unique ?? +@p %% 2 ?? 1 !! -1 !! 0
}

my @möbius = lazy flat '', 1, (2..*).hyper.map: &μ;

# The Task
put "Möbius sequence - First 199 terms:\n",
    @möbius[^200]».fmt('%3s').batch(20).join: "\n";

```

Output:

```
Möbius sequence - First 199 terms:
      1  -1  -1   0  -1   1  -1   0   0   1  -1   0  -1   1   1   0  -1   0  -1
  0   1   1  -1   0   0   1   0   0  -1  -1  -1   0   1   1   1   0  -1   1   1
  0  -1  -1  -1   0   0   1  -1   0   0   0   1   0  -1   0   1   0   1   1  -1
  0  -1   1   0   0   1  -1  -1   0   1  -1  -1   0  -1   1   0   0   1  -1  -1
  0   0   1  -1   0   1   1   1   0  -1   0   1   0   1   1   1   0  -1   0   0
  0  -1  -1  -1   0  -1   1  -1   0  -1  -1   1   0  -1  -1   1   0   0   1   1
  0   0   1   1   0   0   0  -1   0   1  -1  -1   0   1   1   0   0  -1  -1  -1
  0   1   1   1   0   1   1   0   0  -1   0  -1   0   0  -1   1   0  -1   1   1
  0   1   0  -1   0  -1   1  -1   0   0  -1   0   0  -1  -1   0   0   1   1  -1
  0  -1  -1   1   0   1  -1   1   0   0  -1  -1   0  -1   1  -1   0  -1   0  -1
```