Suppose we have a number n, we have to check whether its prime factors only include 2, 3 or 5 or not.
So, if the input is like n = 18, then the output will be True, as 18's prime factors are 2 and 3.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, n): if n < 0: return False factor = [2,3,5] for i in factor: while n%i ==0: n/=i return n==1 ob = Solution() print(ob.solve(18))