mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
Rename Project Euler directories and other dependent changes (#3300)
* Rename all Project Euler directories: Reason: The change was done to maintain consistency throughout the directory and to keep all directories in sorted order. Due to the above change, some config files had to be modified: 'problem_22` -> `problem_022` * Update scripts to pad zeroes in PE directories
This commit is contained in:
34
project_euler/problem_063/sol1.py
Normal file
34
project_euler/problem_063/sol1.py
Normal file
@ -0,0 +1,34 @@
|
||||
"""
|
||||
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 solution(max_base: int = 10, max_power: int = 22) -> int:
|
||||
"""
|
||||
Returns the count of all n-digit numbers which are nth power
|
||||
>>> solution(10, 22)
|
||||
49
|
||||
>>> solution(0, 0)
|
||||
0
|
||||
>>> solution(1, 1)
|
||||
0
|
||||
>>> solution(-1, -1)
|
||||
0
|
||||
"""
|
||||
bases = range(1, max_base)
|
||||
powers = range(1, max_power)
|
||||
return sum(
|
||||
1 for power in powers for base in bases if len(str((base ** power))) == power
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"{solution(10, 22) = }")
|
Reference in New Issue
Block a user