Möbius function: Difference between revisions
Content added Content deleted
m (→{{header|J}}) |
m (→{{header|J}}: concision) |
||
Line 783: | Line 783: | ||
Implementation: |
Implementation: |
||
<lang J>mu=: ({{*/1-y> |
<lang J>mu=: ({{*/1-y>1}} * _1 ^ 2|+/)@q:~&_</lang> |
||
Explanation: _ q: n gives the list of exponents of prime factors of n. (This is an empty list for 1, is 2 0 2 for the number 100 and is 3 1 1 for the number 120.) |
Explanation: _ q: n gives the list of exponents of prime factors of n. (This is an empty list for 1, is 2 0 2 for the number 100 and is 3 1 1 for the number 120.) |
||
In this context +/ is the sum of that list, 2 | +/ is 1 if the sum is odd and 0 if the sum is even. _1^0 is 1 and _1^1 is _1. And, {{*/1-y> |
In this context +/ is the sum of that list, 2 | +/ is 1 if the sum is odd and 0 if the sum is even. _1^0 is 1 and _1^1 is _1. And, {{*/1-y>1}} returns zero if any exponent is at least 2 in magnitude. |
||
Task example: |
Task example: |