Check if a number is divisible by all prime divisors of another number | Javascript program to find if all prime factors of y divide x . ; Returns true if all prime factors of y divide x . ; Driver program to test above functions
function gcd ( a , b ) { return b == 0 ? a : gcd ( b , a % b ) ; } function isDivisible ( x , y ) { if ( y == 1 ) return true ; var z = gcd ( x , y ) ; if ( z == 1 ) return false ; return isDivisible ( x , y / z ) ; } var x = 18 , y = 12 ; if ( isDivisible ( x , y ) ) document . write ( " " ) ; else document . write ( " " ) ;