Skip to content
This repository was archived by the owner on Sep 9, 2021. It is now read-only.

Commit d0d91cf

Browse files
committed
Factorial processing for the big N
1 parent 3cd0ddb commit d0d91cf

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/lab3/calculator/server/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
ERROR = 2
66

77

8+
max_result = 2 ** (64 - 1) - 1
89
# факториал с проверкой на timeout
910
def factorial(n, timeout) -> (int, float, str):
1011
float_n = n
@@ -17,6 +18,8 @@ def factorial(n, timeout) -> (int, float, str):
1718
for i in range(2, n + 1):
1819
if time.time() >= timeout:
1920
return TIMEOUT, result, ""
21+
elif result > max_result:
22+
return ERROR, result, f"Result of {n}! is too large, try to find factorial of smaller number"
2023
else:
2124
result = result * i
2225
return OK, result, ""

0 commit comments

Comments
 (0)