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 f(n): # n = n+1 count = 0 for i in range(n): if i%20 == 0 or i%22 == 0: continue elif str(i).count('2') == len(str(i)): count += 1 return count print(f(10**18))

Questions about programming?Chat with your personal AI assistant