Square Free Number | Returns true if n is a square free number , else returns false . ; If 2 again divides n , then n is not a square free number . ; n must be odd at this point . So we can skip one element ( Note i = i + 2 ) ; Check if i is a prime factor ; If i again divides , then n is not square free ; Driver Code
< ? php function isSquareFree ( $ n ) { if ( $ n % 2 == 0 ) $ n = $ n / 2 ; if ( $ n % 2 == 0 ) return false ; for ( $ i = 3 ; $ i <= sqrt ( $ n ) ; $ i = $ i + 2 ) { if ( $ n % $ i == 0 ) { $ n = $ n / $ i ; if ( $ n % $ i == 0 ) return false ; } } return true ; } $ n = 10 ; if ( isSquareFree ( $ n ) ) echo ( " Yes " ) ; else echo ( " No " ) ; ? >