Count of pairs in a given range with sum of their product and sum equal to their concatenated number | C ++ program to count all the possible pairs with X * Y + ( X + Y ) equal to number formed by concatenating X and Y ; Function for counting pairs ; Count possible values of Y ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countPairs ( int A , int B ) { int countY = 0 , countX = ( B - A ) + 1 , next_val = 9 ; while ( next_val <= B ) { if ( next_val >= A ) { countY += 1 ; } next_val = next_val * 10 + 9 ; } return ( countX * countY ) ; } int main ( ) { int A = 1 ; int B = 16 ; cout << countPairs ( A , B ) ; return 0 ; }