Check if the square of a number is divisible by K or not | Utility gcd ; 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
function gcd ( a , b ) { return b == 0 ? a : gcd ( b , a % b ) ; } function checkDivisible ( x , k ) { var g = gcd ( x , k ) ; k /= g ; if ( x % k == 0 ) { document . write ( " " ) ; } else { document . write ( " " ) ; } } var x = 6 , k = 9 ; checkDivisible ( x , k ) ;