Count of pairs in a given range with sum of their product and sum equal to their concatenated number | Function for counting pairs ; Count possible values of Y ; Driver Code
function countPairs ( A , B ) { var 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 ) ; } var A = 1 ; var B = 16 ; document . write ( countPairs ( A , B ) ) ;