Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add files via upload
  • Loading branch information
Kush1101 authored Aug 27, 2020
commit d55b3763e1b705f2108ae9eb73a88109e7258e35
31 changes: 31 additions & 0 deletions project_euler/problem_63/sol1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number,
134217728=89, is a ninth power.
How many n-digit positive integers exist which are also an nth power?
"""

"""
The maximum base can be 9 because all n-digit numbers < 10^n.
Now 9**23 has 22 digits so the maximum power can be 22.
Using these conclusions, we will calculate the result.
"""


def compute_nums(max_base: int = 10, max_power: int = 22) -> int:
"""
Returns the count of all n-digit numbers which are nth power
>>> compute_nums(10,22)
Comment thread
Kush1101 marked this conversation as resolved.
Outdated
49
"""
bases = list(range(1, max_base))
Comment thread
Kush1101 marked this conversation as resolved.
Outdated
powers = list(range(1, max_power))
count = 0
for base in bases:
for power in powers:
if len(str((base ** power))) == power:
count += 1
return count
Comment thread
Kush1101 marked this conversation as resolved.
Outdated


if __name__ == "__main__":
print(f"{compute_nums(10, 22) = }")