Problem 124 easy with existing prime factors function.
This commit is contained in:
24
python/e124.py
Normal file
24
python/e124.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from lib_prime import prime_factors
|
||||
|
||||
|
||||
def radical(n: int) -> int:
|
||||
fs = prime_factors(n)
|
||||
r = 1
|
||||
for f in set(fs):
|
||||
r *= f
|
||||
return r
|
||||
|
||||
|
||||
def euler_124():
|
||||
assert radical(504) == 42
|
||||
xs = []
|
||||
for n in range(1, 100001):
|
||||
xs.append((radical(n), n))
|
||||
xs = sorted(xs)
|
||||
return xs[10000 - 1][1]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
solution = euler_124()
|
||||
print("e124.py: " + str(solution))
|
||||
assert(solution == 21417)
|
||||
Reference in New Issue
Block a user