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 firstname.lastname@example.org. 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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Check if N can be expressed as product of 3 distinct numbers
- Check if a number can be expressed as a product of exactly K prime divisors
- Maximum of sum and product of digits until number is reduced to a single digit
- 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 all sub-numbers have distinct Digit product
- 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
- Check if a number can be expressed as a^b | Set 2
- Check if a number can be expressed as 2^x + 2^y
- Finding sum of digits of a number until sum becomes single digit
- Check if a number can be expressed as power | Set 2 (Using Log)
- Check if a number can be expressed as x^y (x raised to power y)
- First digit in product of an array of numbers
- Minimum number of single digit primes required whose sum is equal to N
- Last digit of Product of two Large or Small numbers (a * b)
- Largest palindrome which is product of two n-digit numbers
- Largest palindrome which is product of two N-digit numbers : Set 2
- Count of Numbers in Range where first digit is equal to last digit of the number
- Maximum number with same digit factorial product
Improved By : Sam007