human
Program for Mobius Function | Python Program to evaluate Mobius def M ( N ) = 1 if N = 1 M ( N ) = 0 if any prime factor of N is contained twice M ( N ) = ( - 1 ) ^ ( no of distinctprime factors ).
def to check if n is prime or not.
Handling 2 separately.
If 2 ^ 2 also divides N.
Check for all other prime factors.
If i divides n.
If i ^ 2 also divides N.
Driver Code"
Solution in Python:
assistant
#Here is code to program for Mobius Function and the other steps required.
 import math
def isPrime ( n ) :
	if ( n < 2 ) :
		return False
	for i in range ( 2 , n + 1 ) :
		if ( n % i == 0 ) :
			return False
		i = i * i
	return True
def mobius ( n ) :
	p = 0
	if ( n % 2 == 0 ) :
		n = int ( n / 2 )
		p = p + 1
		if ( n % 2 == 0 ) :
			return 0
	for i in range ( 3 , int ( math . sqrt ( n ) ) + 1 ) :
		if ( n % i == 0 ) :
			n = int ( n / i )
			p = p + 1
			if ( n % i == 0 ) :
				return 0
		i = i + 2
	if ( p % 2 == 0 ) :
		return - 1
	else :
		return 1
N = 17
print ( " Mobius defs M ( N ) at N = { } is : { } " . format ( N , mobius ( N ) ) ) ;
print ( " Mobius defs M ( N ) at N = 25 is : { } " . format ( mobius ( 25 ) ) ) ;
print ( " Mobius defs M ( N ) at N = 6 is : { } " . format ( mobius ( 6 ) ) ) ;