MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / solution

Function solution

project_euler/problem_063/sol1.py:14–30  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

12
13
14def 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
33if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected