Write and test a C implementation of the Mobius function Mn

Write and test a C implementation of the Mobius function M(n) defined as follows

M(n) = 1 if n = 1          

= 0 if any prime factor is contained in N more than once

= (1)p if n is the product of p different prime factors

Examples

M(78) = 1     78 = 2 * 3 * 13                  

M(34) = 1      34 = 2 * 17               

M(45) = 0       45 = 3 * 3 * 5

The first values of M(n) are shown in this table n 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

M(n) 1 1 1 0 1 1 1 0 0 1 1 0 1 1 1 0 1 0 1 0

Extra credit:    Using random numbers, estimate the probabilities that M(n) returns 1, 0, +1

Solution

M(n) Function code:

Hope my answer helped you.Any further doubts,please feel free to ask us.We will love to help you

Write and test a C implementation of the Mobius function M(n) defined as follows M(n) = 1 if n = 1 = 0 if any prime factor is contained in N more than once = (1

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site