Count of pairs of integers up to X and Y that generates equal Quotient and Remainder | Function to calculate the number of pairs satisfying ( m / n = m % n ) ; Iterate from 1 to sqrt ( x ) ; Combining the conditions - 1 ) n > k 2 ) n <= y 3 ) n <= ( x / k - 1 ) ; Driver code
function countOfPairs ( x , y ) { var count = 0 ; var k ; for ( k = 1 ; k * k <= x ; ++ k ) { count += Math . max ( 0 , Math . min ( y , x / k - 1 ) - k ) ; } document . write ( count + " " ) ; } var x = 4 ; var y = 5 ; countOfPairs ( x , y ) ;