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

Function solution

project_euler/problem_129/sol1.py:37–53  ·  view source on GitHub ↗

Return the least value of n for which least_divisible_repunit(n) first exceeds limit. >>> solution(10) 17 >>> solution(100) 109 >>> solution(1000) 1017

(limit: int = 1000000)

Source from the content-addressed store, hash-verified

35
36
37def solution(limit: int = 1000000) -> int:
38 """
39 Return the least value of n for which least_divisible_repunit(n)
40 first exceeds limit.
41 >>> solution(10)
42 17
43 >>> solution(100)
44 109
45 >>> solution(1000)
46 1017
47 """
48 divisor = limit - 1
49 if divisor % 2 == 0:
50 divisor += 1
51 while least_divisible_repunit(divisor) <= limit:
52 divisor += 2
53 return divisor
54
55
56if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

least_divisible_repunitFunction · 0.85

Tested by

no test coverage detected