Program for Mobius Function | Returns value of mobius ( ) ; 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
< ? php function mobius ( $ n ) { $ p = 0 ; if ( $ n % 2 == 0 ) { $ n = $ n / 2 ; $ p ++ ; if ( $ n % 2 == 0 ) return 0 ; } for ( $ i = 3 ; $ i <= sqrt ( $ n ) ; $ i = $ i + 2 ) { if ( $ n % $ i == 0 ) { $ n = $ n / $ i ; $ p ++ ; if ( $ n % $ i == 0 ) return 0 ; } } return ( $ p % 2 == 0 ) ? -1 : 1 ; } $ N = 17 ; echo " Mobius ▁ Functions ▁ M ( N ) ▁ at ▁ N ▁ = ▁ " , $ N , " ▁ is : ▁ " , mobius ( $ N ) , " STRNEWLINE " ; echo " Mobius ▁ Functions ▁ M ( N ) ▁ at ▁ N ▁ = ▁ " , 25 , " ▁ is : ▁ " , mobius ( 25 ) , " STRNEWLINE " ; echo " Mobius ▁ Functions ▁ M ( N ) ▁ at ▁ N ▁ = ▁ " , 6 , " ▁ is : ▁ " , mobius ( 6 ) ; ? >