Given an integer N, the task is to find out whether the given number is an Ugly number or not .
Ugly numbers are numbers whose only prime factors are 2, 3 or 5.
Input: N = 14
14 is not ugly since it includes another prime factor 7.
Input: N = 6
6 is a ugly since it includes 2 and 3.
Approach: The idea is to use recursion to solve this problem and check if a number is divisible by 2, 3 or 5. If yes then divide the number by that and recursively check that a number is an ugly number or not. If at any time, there is no such divisor, then return false, else true.
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.
- Super Ugly Number (Number whose prime factors are in given set)
- Program to check whether the given number is Buzz Number or not
- Check whether a given number N is a Nude Number or not
- Check whether the binary equivalent of a number ends with given string or not
- Check whether triangle is valid or not if sides are given
- Check whether two strings are equivalent or not according to given condition
- Check Whether a number is Duck Number or not
- Check whether a number has exactly three distinct factors or not
- Check whether a number is semiprime or not
- Check whether the number formed by concatenating two numbers is a perfect square or not
- Python program to check whether a number is Prime or not
- C Program to check whether a number is a Perfect Cube or not
- Check whether a point lies inside a sphere or not
- Check whether the two Binary Search Trees are Identical or Not
- Check whether a + b = c or not after removing all zeroes from a,b and c
- Check whether the Average Character of the String is present or not
- Check whether a Matrix is a Latin Square or not
- Check whether given floating point number is even or odd
- Queries to find whether a number has exactly four distinct factors or not
- Check whether the given character is in upper case, lower case or non alphabetic character
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.