Given two positive integers N1 and N2, the task is to find the sum of the products of the same placed digits of the two numbers.
Note: For numbers of unequal length, the preceding digits of the smaller number needs to be treated as 0.
Input: N1 = 5, N2 = 67
At one’s place, we have digits 5 and 7, their product is 35. At ten’s place we have 6 in N2. As N1 has no digit at ten’s place, 6 will be multiplied with 0, leading to no effect on the sum. Hence, the calculated sum is 35.
Input: N1 = 25, N2 = 1548
Sum = 5 * 8 + 2 * 4 + 0 * 5 + 0 * 1 = 48.
To solve the problem mentioned above, we need to follow the steps below:
- Extract the rightmost digits of the two numbers and multiply them and add their product to sum.
- Now remove the digit.
- Keep repeating the above two steps until one of them is reduced to 0. Then, print the final value of sum calculated.
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.
- Spy Number (Sum and Products of Digits are same)
- Minimize the Sum of all the subarrays made up of the products of same-indexed elements
- Minimum digits to be removed to make either all digits or alternating digits same
- Sum of all products of the Binomial Coefficients of two numbers up to K
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Minimum number of digits to be removed so that no two consecutive digits are same
- Maximum Sum of Products of Two Arrays
- Maximize the sum of products of the degrees between any two vertices of the tree
- Numbers with sum of digits equal to the sum of digits of its all prime factor
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Find the number of rectangles of size 2*1 which can be placed inside a rectangle of size n*m
- Maximum non-attacking Rooks that can be placed on an N*N Chessboard
- Check if all objects of type A and B can be placed on N shelves
- Count of smaller rectangles that can be placed inside a bigger rectangle
- Check if two numbers have same number of digits
- Sum of pairwise products
- Maximize sum of pairwise products generated from the given Arrays
- Sum of all ordered pair-products from a given array
- Count distinct pairs from two arrays having same sum of digits
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.