Solution to problem 63 in Python

This commit is contained in:
David Doblas Jiménez 2022-08-05 21:58:00 +02:00
parent 8ff023990b
commit 286d1b564b

35
src/Python/Problem063.py Normal file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env python3
"""
Created on 05 Aug 2022
@author: David Doblas Jiménez
@email: daviddoji@pm.me
Solution for problem 63 of Project Euler
https://projecteuler.net/problem=63
"""
from utils import timeit
@timeit("Problem 63")
def compute():
"""
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?
"""
ans = 0
# no need to go higher than 10, because 10**2 = 100
for number in range(1, 10):
for pow in range(1, 30):
if len(str(number**pow)) == pow:
ans += 1
return ans
if __name__ == "__main__":
print(f"Result for Problem 63: {compute()}")