MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_551/sol1.py:170–196  ·  view source on GitHub ↗

returns n-th term of sequence >>> solution(10) 62 >>> solution(10**6) 31054319 >>> solution(10**15) 73597483551591773

(n: int = 10**15)

Source from the content-addressed store, hash-verified

168
169
170def solution(n: int = 10**15) -> int:
171 """
172 returns n-th term of sequence
173
174 >>> solution(10)
175 62
176
177 >>> solution(10**6)
178 31054319
179
180 >>> solution(10**15)
181 73597483551591773
182 """
183
184 digits = [1]
185 i = 1
186 dn = 0
187 while True:
188 _diff, terms_jumped = next_term(digits, 20, i + dn, n)
189 dn += terms_jumped
190 if dn == n - i:
191 break
192
193 a_n = 0
194 for j in range(len(digits)):
195 a_n += digits[j] * 10**j
196 return a_n
197
198
199if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

next_termFunction · 0.85

Tested by

no test coverage detected