Class name: Mobius
Method name: mu
Parameters: int
Returns: int
Implement a class Mobius, which has a method mu.
Method signature: int mu(int N) (be sure you declare your method public)
The fundamental Theorem of Arithmetic says that for every positive integer N
greater than one, N can be written uniquely as (p1 ^ k1) * (p2 ^ k2) * ... *
(pr ^ kr) where p1, p2, ..., pr are distinct primes, and k1, k2, ..., kr are
positive integers.
Example:
2 = 2 ^ 1
4 = 2 ^ 2
10 = (5 ^ 1) * (2 ^ 1)
25 = (5 ^ 2)
180 = (2 ^ 2) * (3 ^ 2) * (5 ^ 1)
mu is defined as follows:
mu(1) = 1
if N > 1, then
mu(N) = 0, if N has a square factor.
Example: 180 has a square factor, since (2 ^ 2) = 4 is a factor of 180
27 has a square factor, 9 ( 27 = (3 ^ 3) = (3 ^ 2) * (3 ^ 1) )
if N does not have a square factor (all roots of N are unique primes), then
mu(N) = (-1) ^ (k1 + k2 + ... + kr)
Example:
mu(2) = (-1) ^ 1 = -1, since 2 = (2 ^ 1)
mu(6) = (-1) ^ 2 = 1, since 6 = (2 ^ 1) * (3 ^ 1)
mu(91) = (-1) ^ 2 = 1, since 91 = (7 ^ 1) * (13 ^ 1)
Note that if N is prime, then mu(N) = -1
SPECIFICS/BOUNDS:
*mu takes an int (N) as a parameter and returns an int.
*N must be between 1 and 1000, inclusive.
TEST CASES:
mu(1) = 1
mu(2) = -1
mu(3) = -1
mu(4) = 0
mu(5) = -1
mu(6) = 1
mu(7) = -1
mu(8) = 0
mu(9) = 0
mu(10) = 1
mu(81) = 0
mu(105) = -1
mu(109) = -1
mu(999) = 0
mu(1000) = 0