Count possible values of K such that X | Function to count integers K satisfying given equation ; Calculate the absoluter difference between a and b ; Iterate till sqrt of the difference ; Return the count ; Driver Code
function condition ( a , b ) { let d = Math . abs ( a - b ) , count = 0 ; for ( let i = 1 ; i <= Math . sqrt ( d ) ; i ++ ) { if ( d % i == 0 ) { if ( d / i == i ) count += 1 ; else count += 2 ; } } return count ; } let x = 2 , y = 6 ; document . write ( condition ( x , y ) ) ;