Largest Divisor of a Number not divisible by a perfect square | Function to find the largest divisor not divisible by any perfect square greater than 1 ; If the number is divisible by i * i , then remove one i ; Now all squares are removed from n ; Driver Code
< ? php function findLargestDivisor ( $ n ) { for ( $ i = 2 ; $ i < sqrt ( $ n ) + 1 ; $ i ++ ) { while ( $ n % ( $ i * $ i ) == 0 ) { $ n = $ n / $ i ; } } return $ n ; } $ n = 12 ; echo ( findLargestDivisor ( $ n ) ) ; echo ( " STRNEWLINE " ) ; $ n = 97 ; echo ( findLargestDivisor ( $ n ) ) ; ? >