// you’re reading...
1 Star2 Stars3 Stars4 Stars5 Stars (28 votes, average: 4.86 out of 5)
Loading...

Project Euler Solutions

Project Euler 63 Solution

Project Euler 63 Solution

Project Euler 63: Count how many n-digit positive integers exist which are also an nth power


Problem Description

The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is a ninth power.

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

Analysis

One way to know how many digits a number has is to use the formula: int(log10 n) +1. For this problem n cannot be greater than 10 since 10n is always n+1 digits long.

So we need to create a function such that f(n) = upper limit of n. Using our log function and using 9 as an example we define f(9) as int (1 / (1 – log10 9)) or 21 such that 9n < 10n-1. Thus 9n is n digits long when n ≤ 21. We repeat this same process for 1 through 8 and sum the results for an answer.

Project Euler 63 Solution

Runs < 0.001 seconds in Python 2.7.
download arrowUse this link to get the Project Euler 63 Solution Python 2.7 source.

Afterthoughts

    No afterthoughts yet.
Project Euler 63 Solution last updated

Discussion

No comments yet.

Post a comment