Problem #63
Difficulty: 5%
Powerful Digit Counts
Solution Language: Python
Problem Statement
The 5-digit number, 16807 = 7⁵, is also a fifth power. Similarly, the 9-digit number, 134217728 = 8⁹, is a ninth power.
How many n-digit positive integers exist which are also an nth power?
Approach
The solution involves:
- Recognizing that for n-digit numbers to be nth powers, the base must be less than 10
- For each base b (1-9), computing b^n for increasing n
- Checking if the number of digits equals n
- Stopping when b^n has fewer than n digits (this happens eventually for all bases)
- Counting all valid combinations