Returns the number of blue discs for the first arrangement to contain over min_total discs in total >>> solution(2) 3 >>> solution(4) 15 >>> solution(21) 85
(min_total: int = 10**12)
| 14 | |
| 15 | |
| 16 | def solution(min_total: int = 10**12) -> int: |
| 17 | """ |
| 18 | Returns the number of blue discs for the first arrangement to contain |
| 19 | over min_total discs in total |
| 20 | |
| 21 | >>> solution(2) |
| 22 | 3 |
| 23 | |
| 24 | >>> solution(4) |
| 25 | 15 |
| 26 | |
| 27 | >>> solution(21) |
| 28 | 85 |
| 29 | """ |
| 30 | |
| 31 | prev_numerator = 1 |
| 32 | prev_denominator = 0 |
| 33 | |
| 34 | numerator = 1 |
| 35 | denominator = 1 |
| 36 | |
| 37 | while numerator <= 2 * min_total - 1: |
| 38 | prev_numerator += 2 * numerator |
| 39 | numerator += 2 * prev_numerator |
| 40 | |
| 41 | prev_denominator += 2 * denominator |
| 42 | denominator += 2 * prev_denominator |
| 43 | |
| 44 | return (denominator + 1) // 2 |
| 45 | |
| 46 | |
| 47 | if __name__ == "__main__": |