From 56ea34050959bbd97e6aae9fe8f2d865efb43a48 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Fri, 15 Jan 2021 13:18:42 +0100 Subject: problem 63 in python --- python/063-powerful_digit_counts.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 python/063-powerful_digit_counts.py (limited to 'python') diff --git a/python/063-powerful_digit_counts.py b/python/063-powerful_digit_counts.py new file mode 100644 index 0000000..4dc0b76 --- /dev/null +++ b/python/063-powerful_digit_counts.py @@ -0,0 +1,22 @@ +### +# Powerful digit counts +# Problem 63 +# +# 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? +### + +import itertools + +count = 0 + +for n in itertools.count(1): + for e in range(1, 400): + x = n ** e + l = len(str(x)) + if l == e: + print(n, "^", e, "=", x) + count += 1 + print(count) + elif l > e: + break -- cgit