Returns the last 8 digits of the hyperexponentiation of base by height, i.e. the number base↑↑height: >>> solution(base=3, height=2) 27 >>> solution(base=3, height=3) 97484987 >>> solution(base=123, height=456, digits=4) 2547
(base: int = 1777, height: int = 1855, digits: int = 8)
| 43 | |
| 44 | |
| 45 | def solution(base: int = 1777, height: int = 1855, digits: int = 8) -> int: |
| 46 | """ |
| 47 | Returns the last 8 digits of the hyperexponentiation of base by |
| 48 | height, i.e. the number base↑↑height: |
| 49 | |
| 50 | >>> solution(base=3, height=2) |
| 51 | 27 |
| 52 | >>> solution(base=3, height=3) |
| 53 | 97484987 |
| 54 | >>> solution(base=123, height=456, digits=4) |
| 55 | 2547 |
| 56 | """ |
| 57 | |
| 58 | # calculate base↑↑height by right-assiciative repeated modular |
| 59 | # exponentiation |
| 60 | result = base |
| 61 | for _ in range(1, height): |
| 62 | result = _modexpt(base, result, 10**digits) |
| 63 | |
| 64 | return result |
| 65 | |
| 66 | |
| 67 | if __name__ == "__main__": |