-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathV2.py
More file actions
23 lines (20 loc) · 656 Bytes
/
V2.py
File metadata and controls
23 lines (20 loc) · 656 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import math
def is_factorial(x):
"""Check if x is a factorial of any number."""
if x <= 0:
return None
n = 1
factorial = 1
while factorial < x:
n += 1
factorial *= n
return n if factorial == x else None
def brocard_problem_solver(start, end):
"""Solve Brocard's problem for numbers in a given range."""
for number in range(start, end + 1):
x = number**2 - 1
result = is_factorial(x)
if result is not None:
print(f"{number} is a solution to Brocard's problem! (n! = {x}, n = {result})")
# Define the range to search for solutions
brocard_problem_solver(2, 1000)