Given two integers A and B, the task is to calculate the number of pairs (a, b) such that 1 ≤ a ≤ A, 1 ≤ b ≤ B and the equation (a * b) + a + b = concat(a, b) is true where conc(a, b) is the concatenation of a and b (for example, conc(12, 23) = 1223, conc(100, 11) = 10011). Note that a and b should not contain any leading zeroes.
Input: A = 1, B = 12
There exists only one pair (1, 9) satisfying
the equation ((1 * 9) + 1 + 9 = 19)
Input: A = 2, B = 8
There doesn’t exist any pair satisfying the equation.
Approach: It can be observed that the above (a * b + a + b = conc(a, b)) will only be satisfied when the digits of an integer ≤ b contains only 9. Simply, calculate the number of digits (≤ b) containing only 9 and multiply with the integer a.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find the maximum sum (a+b) for a given input integer N satisfying the given condition
- Check if elements of an array can be arranged satisfying the given condition
- Count valid pairs in the array satisfying given conditions
- Count of Ordered Pairs (X, Y) satisfying the Equation 1/X + 1/Y = 1/N
- Count triplet pairs (A, B, C) of points in 2-D space that satisfy the given condition
- Count index pairs which satisfy the given condition
- Queries to count distinct Binary Strings of all lengths from N to M satisfying given properties
- Number of K's such that the given array can be divided into two sets satisfying the given conditions
- Pairs from an array that satisfy the given condition
- Count of numbers satisfying m + sum(m) + sum(sum(m)) = N
- Generate N integers satisfying the given conditions
- Smallest positive integer X satisfying the given equation
- Split N as the sum of K numbers satisfying the given conditions
- Count of sub-sequences which satisfy the given condition
- Count all possible N digit numbers that satisfy the given condition
- Count of indices in an array that satisfy the given condition
- Find x and y satisfying ax + by = n
- Sum of minimum value of x and y satisfying the equation ax + by = c
- Smallest index in the given array that satisfies the given condition
- Compute the maximum power with a given condition
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.