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)
| 15 | |
| 16 | |
| 17 | def 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 | |
| 37 | def solution(limit: int = 1000000) -> int: |