Python Implementation of Problem 63

View source code here on GitHub!

Problem Solution

Project Euler Problem 63

Problem:

The 5-digit number, 16807 = 7**5, is also a fifth power. Similarly, the 9-digit number, 134217728 = 8**9, is a ninth power.

How many n-digit positive integers exist which are also an nth power?

python.src.p0063.main() int
 1"""
 2Project Euler Problem 63
 3
 4Problem:
 5
 6The 5-digit number, 16807 = 7**5, is also a fifth power.
 7Similarly, the 9-digit number, 134217728 = 8**9, is a ninth power.
 8
 9How many n-digit positive integers exist which are also an nth power?
10"""
11from typing import Dict, Tuple
12
13
14def main() -> int:
15    seen: Dict[Tuple[int, int], int] = {}
16    for x in range(1, 10):
17        for n in range(1, 100):
18            if len(str(x**n)) == n:
19                seen[x, n] = x**n
20    return len(seen)

Tags: power