We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent d50f053 commit de068faCopy full SHA for de068fa
MyOnlineSubmissions/ProjectEuler/63.py
@@ -0,0 +1,19 @@
1
+# The 5-digit number, 16807=7^5, is also a fifth power.
2
+# Similarly, the 9-digit number, 134217728=8^9, is a ninth power.
3
+# How many n-digit positive integers exist which are also an nth power?
4
+
5
+def digits(x):
6
+ ans = 0
7
+ while x > 0:
8
+ x //= 10
9
+ ans += 1
10
+ return ans
11
12
+ans = 1 # 1^1 = 1
13
+for k in range(2, 11):
14
+ for p in range(1, 22):
15
+ # check if k^p has p digits
16
+ if digits(pow(k, p)) == p:
17
18
+ print(f'{k}^{p} = {pow(k, p)} has {p} digits.')
19
+print(ans)
0 commit comments