returns n-th term of sequence >>> solution(10) 62 >>> solution(10**6) 31054319 >>> solution(10**15) 73597483551591773
(n: int = 10**15)
| 168 | |
| 169 | |
| 170 | def 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 | |
| 199 | if __name__ == "__main__": |