Skip to content

Commit de068fa

Browse files
committed
PE63 - analysis, logarithm, algebra, interview
1 parent d50f053 commit de068fa

File tree

1 file changed

+19
-0
lines changed
  • MyOnlineSubmissions/ProjectEuler

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
ans += 1
18+
print(f'{k}^{p} = {pow(k, p)} has {p} digits.')
19+
print(ans)

0 commit comments

Comments
 (0)