Given a positive integer N. The task is to find sum and product of digits of the number which evenly divides the number n.
Input: N = 12 Output: Sum = 3, product = 2 1 and 2 divide 12. So, their sum is 3 and product is 2. Input: N = 1012 Output: Sum = 4, product = 2 1, 1 and 2 divide 1012.
Approach: The idea is to find the each digit of the number n by modulus 10 and then check whether it divides n or not. Accordingly, add it to the sum and multiply it with the product. Notice that the digit can be 0, so take care of that case.
Below is the implementation of the above approach:
Sum = 4 Product = 2
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.
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Divide a number into two parts such that sum of digits is maximum
- Minimum digits to be removed to make either all digits or alternating digits same
- Smallest number with given sum of digits and sum of square of digits
- Find count of digits in a number that divide the number
- Count digits in given number N which divide N
- Check if all digits of a number divide it
- Find smallest number with given number of digits and sum of digits
- Find the Largest number with given number of digits and sum of digits
- Find smallest number with given number of digits and sum of digits under given constraints
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- 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
- Product of all sorted subsets of size K using elements whose index divide K completely
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Maximum of sum and product of digits until number is reduced to a single digit
- Maximum sum and product of the M consecutive digits in a number
- Check if the sum of digits of number is divisible by all of its digits
- Sum of the digits of square of the given number which has only 1's as its digits
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.