Given a non-negative number n. The problem is to check whether the given number n can be expressed as a product of single digit numbers or not.
Input : n = 24 Output : Yes Different combinations are: (8*3) and (6*4) Input : 68 Output : No To represent 68 as product of number, 17 must be included which is a two digit number.
Approach: We have to check whether the number n has no prime factors other than 2, 3, 5, 7. For this we repeatedly divide the number n by (2, 3, 5, 7) until it cannot be further divided by these numbers. After this process if n == 1, then it can be expressed as a product of single digit numbers, else if it is greater than 1, then it cannot be expressed.
Time Complexity: O(num), where num is the number of prime factors (2, 3, 5, 7) of n.
This article is contributed by Ayush Jauhari. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Maximum of sum and product of digits until number is reduced to a single digit
- Check if all sub-numbers have distinct Digit product
- Check if a number can be expressed as sum two abundant numbers
- Check if a number can be expressed as a sum of consecutive numbers
- Check if a prime number can be expressed as sum of two Prime Numbers
- Numbers less than N that are perfect cubes and the sum of their digits reduced to a single digit is 1
- Finding sum of digits of a number until sum becomes single digit
- Check if a number can be expressed as a^b | Set 2
- Check if a number can be expressed as 2^x + 2^y
- First digit in product of an array of numbers
- Check if a number can be expressed as power | Set 2 (Using Log)
- Minimum number of single digit primes required whose sum is equal to N
- Largest palindrome which is product of two n-digit numbers
- Last digit of Product of two Large or Small numbers (a * b)
- Check if a number can be expressed as x^y (x raised to power y)
Improved By : Sam007