MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_095/sol1.py:134–160  ·  view source on GitHub ↗

Runs the calculation for numbers <= `max_num`. >>> solution(10) 6 >>> solution(200000) 12496

(max_num: int = 1000000)

Source from the content-addressed store, hash-verified

132
133
134def solution(max_num: int = 1000000) -> int:
135 """
136 Runs the calculation for numbers <= `max_num`.
137
138 >>> solution(10)
139 6
140 >>> solution(200000)
141 12496
142 """
143
144 primes = generate_primes(max_num)
145 chain = [0] * (max_num + 1)
146 for prime_idx, prime in enumerate(primes):
147 if prime**2 > max_num:
148 break
149
150 multiply(
151 chain=chain,
152 primes=primes,
153 min_prime_idx=prime_idx,
154 prev_num=1,
155 max_num=max_num,
156 prev_sum=0,
157 primes_degrees={},
158 )
159
160 return find_longest_chain(chain=chain, max_num=max_num)
161
162
163if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 3

generate_primesFunction · 0.85
find_longest_chainFunction · 0.85
multiplyFunction · 0.70

Tested by

no test coverage detected