Returns the count of all n-digit numbers which are nth power >>> solution(10, 22) 49 >>> solution(0, 0) 0 >>> solution(1, 1) 0 >>> solution(-1, -1) 0
(max_base: int = 10, max_power: int = 22)
| 12 | |
| 13 | |
| 14 | def solution(max_base: int = 10, max_power: int = 22) -> int: |
| 15 | """ |
| 16 | Returns the count of all n-digit numbers which are nth power |
| 17 | >>> solution(10, 22) |
| 18 | 49 |
| 19 | >>> solution(0, 0) |
| 20 | 0 |
| 21 | >>> solution(1, 1) |
| 22 | 0 |
| 23 | >>> solution(-1, -1) |
| 24 | 0 |
| 25 | """ |
| 26 | bases = range(1, max_base) |
| 27 | powers = range(1, max_power) |
| 28 | return sum( |
| 29 | 1 for power in powers for base in bases if len(str(base**power)) == power |
| 30 | ) |
| 31 | |
| 32 | |
| 33 | if __name__ == "__main__": |