generate functionWed, 08 Mar 2023

A good number is defined as a natural number where each digit is 0 or 2. The number of natural numbers that are good numbers from 1 to n and not divisible by either 20 or 22 is defined as f(n). f(10^18) is calculated and output using an algorithm that efficiently finds f(n).

def good_number(n): good = "0" not_good = ['1', '3', '4', '5', '6', '7', '8', '9'] for i in str(n): if i in good: return True elif i in not_good: return False

Questions about programming?Chat with your personal AI assistant