Largest Divisor of a Number not divisible by a perfect square | Efficient Java Program to find the largest divisor not divisible by any perfect square greater than 1 ; 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
public class GFG { static int findLargestDivisor ( int n ) { for ( int i = 2 ; i < Math . sqrt ( n ) + 1 ; i ++ ) { while ( n % ( i * i ) == 0 ) { n = n / i ; } } return n ; } public static void main ( String args [ ] ) { int n = 12 ; System . out . println ( findLargestDivisor ( n ) ) ; n = 97 ; System . out . println ( findLargestDivisor ( n ) ) ; } }