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

Function least_divisible_repunit

project_euler/problem_129/sol1.py:17–34  ·  view source on GitHub ↗

Return the least value k such that the Repunit of length k is divisible by divisor. >>> least_divisible_repunit(7) 6 >>> least_divisible_repunit(41) 5 >>> least_divisible_repunit(1234567) 34020

(divisor: int)

Source from the content-addressed store, hash-verified

15
16
17def least_divisible_repunit(divisor: int) -> int:
18 """
19 Return the least value k such that the Repunit of length k is divisible by divisor.
20 >>> least_divisible_repunit(7)
21 6
22 >>> least_divisible_repunit(41)
23 5
24 >>> least_divisible_repunit(1234567)
25 34020
26 """
27 if divisor % 5 == 0 or divisor % 2 == 0:
28 return 0
29 repunit = 1
30 repunit_index = 1
31 while repunit:
32 repunit = (10 * repunit + 1) % divisor
33 repunit_index += 1
34 return repunit_index
35
36
37def solution(limit: int = 1000000) -> int:

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected