Count of pairs of integers up to X and Y that generates equal Quotient and Remainder | C ++ Program for the above approach ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void countOfPairs ( int x , int y ) { int count = 0 ; for ( int k = 1 ; k * k <= x ; ++ k ) { count += max ( 0 , min ( y , x / k - 1 ) - k ) ; } cout << count << " STRNEWLINE " ; } int main ( ) { int x = 4 ; int y = 5 ; countOfPairs ( x , y ) ; return 0 ; }