Generation

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).

from collections import defaultdict from collections import Counter from itertools import accumulate def f(n): c = Counter(str(n)) return c["0"] + c["2"] def f(n): return sum([f(int(i)) for i in str(n)]) def f(n): if n <= 1: return 0 return f(n-1) + f(n-2) def f(n): if n <= 1: return 0 elif n == 2: return 1 else: return f(n-1) + f(n-2) def f(n): if n <= 1: return 0 a = 1 b = 1 for i in range(n-2): c = a + b a = b b = c return c def f(n): if n <= 1: return 0 a = 1 b = 1 for i in

Questions about programming?Chat with your personal AI assistant