49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
'''
|
|
Alex loves lucky numbers. Lucky numbers are positive integers that contain only the digits 4 and 7 in their decimal representation.
|
|
|
|
For example, numbers like 47, 744, and 4 are lucky, while numbers like 5, 17, and 467 are not.
|
|
|
|
Alex calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number n is almost lucky,
|
|
return YES if its almost lucky and NO in the opposite case.
|
|
|
|
Example 1
|
|
Input:
|
|
47
|
|
Output:
|
|
YES
|
|
Example 2
|
|
Input:
|
|
16
|
|
Output:
|
|
YES
|
|
Example 3
|
|
Input:
|
|
78
|
|
Output:
|
|
NO
|
|
'''
|
|
|
|
class Solution(object):
|
|
def solve(self, n):
|
|
# Function to check if a number is lucky
|
|
def is_lucky(num):
|
|
return all(digit in '47' for digit in str(num))
|
|
|
|
# Generate lucky numbers up to n
|
|
lucky_numbers = [i for i in range(1, n + 1) if is_lucky(i)]
|
|
|
|
# Check if n is almost lucky
|
|
for lucky in lucky_numbers:
|
|
if n % lucky == 0:
|
|
return "YES"
|
|
|
|
return "NO"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
n = int(input())
|
|
solution = Solution()
|
|
print(solution.solve(n)) # Output: YES or NO based on the input number n
|
|
|
|
# Example usage:
|
|
# n = 47 |