Check if the square of a number is divisible by K or not | Java implementation to check if the square of X is divisible by K ; Function to return if square of X is divisible by K ; Finding gcd of x and k ; Dividing k by their gcd ; Check for divisibility of X by reduced K ; Driver Code
class GFG { static void checkDivisible ( int x , int k ) { int g = __gcd ( x , k ) ; k /= g ; if ( x % k == 0 ) { System . out . print ( "YESNEW_LINE"); } else { System . out . print ( "NONEW_LINE"); } } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int x = 6 , k = 9 ; checkDivisible ( x , k ) ; } }