Returns the last n digits of NUMBER. >>> solution() '8739992577' >>> solution(8) '39992577' >>> solution(1) '7' >>> solution(-1) Traceback (most recent call last): ... ValueError: Invalid input >>> solution(8.3) Traceback (most re
(n: int = 10)
| 11 | |
| 12 | |
| 13 | def solution(n: int = 10) -> str: |
| 14 | """ |
| 15 | Returns the last n digits of NUMBER. |
| 16 | >>> solution() |
| 17 | '8739992577' |
| 18 | >>> solution(8) |
| 19 | '39992577' |
| 20 | >>> solution(1) |
| 21 | '7' |
| 22 | >>> solution(-1) |
| 23 | Traceback (most recent call last): |
| 24 | ... |
| 25 | ValueError: Invalid input |
| 26 | >>> solution(8.3) |
| 27 | Traceback (most recent call last): |
| 28 | ... |
| 29 | ValueError: Invalid input |
| 30 | >>> solution("a") |
| 31 | Traceback (most recent call last): |
| 32 | ... |
| 33 | ValueError: Invalid input |
| 34 | """ |
| 35 | if not isinstance(n, int) or n < 0: |
| 36 | raise ValueError("Invalid input") |
| 37 | modulus = 10**n |
| 38 | number = 28433 * (pow(2, 7830457, modulus)) + 1 |
| 39 | return str(number % modulus) |
| 40 | |
| 41 | |
| 42 | if __name__ == "__main__": |