MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Mu

Function Mu

math/mobius.go:23–40  ·  view source on GitHub ↗

Mu is the Mobius function This function returns μ(n) for given number

(n int)

Source from the content-addressed store, hash-verified

21// Mu is the Mobius function
22// This function returns μ(n) for given number
23func Mu(n int) int {
24 if n <= 1 {
25 return 1
26 }
27 var primeFactorCount int
28 for i := 1; i <= n; i++ {
29 if n%i == 0 && prime.OptimizedTrialDivision(int64(i)) {
30 if n%(i*i) == 0 {
31 return 0
32 }
33 primeFactorCount += 1
34 }
35 }
36 if primeFactorCount%2 == 0 {
37 return 1
38 }
39 return -1
40}

Callers

nothing calls this directly

Calls 1

OptimizedTrialDivisionFunction · 0.92

Tested by

no test coverage detected