Skip to content

Commit 992bd3d

Browse files
committed
Add default arg and typehints for 2nd soln of PE TheAlgorithms#3
1 parent 736d371 commit 992bd3d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: project_euler/problem_03/sol2.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88

99

10-
def solution(n):
10+
def solution(n: int = 600851475143) -> int:
1111
"""Returns the largest prime factor of a given number n.
1212
1313
>>> solution(13195)
@@ -41,15 +41,19 @@ def solution(n):
4141
raise TypeError("Parameter n must be int or passive of cast to int.")
4242
if n <= 0:
4343
raise ValueError("Parameter n must be greater or equal to one.")
44+
4445
prime = 1
4546
i = 2
47+
4648
while i * i <= n:
4749
while n % i == 0:
4850
prime = i
4951
n //= i
5052
i += 1
53+
5154
if n > 1:
5255
prime = n
56+
5357
return int(prime)
5458

5559

0 commit comments

Comments
 (0)