aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-01-15 13:18:42 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-01-15 13:18:42 +0100
commit56ea34050959bbd97e6aae9fe8f2d865efb43a48 (patch)
treea1d8d8d9635441e962b18b9673790d2415745259
parent47dc12861bc801e6a76e22e8915a322159b2342e (diff)
downloadproject_euler-56ea34050959bbd97e6aae9fe8f2d865efb43a48.tar.gz
project_euler-56ea34050959bbd97e6aae9fe8f2d865efb43a48.tar.bz2
project_euler-56ea34050959bbd97e6aae9fe8f2d865efb43a48.zip
problem 63 in python
-rw-r--r--python/063-powerful_digit_counts.py22
1 files changed, 22 insertions, 0 deletions
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