-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathV5.py
More file actions
25 lines (21 loc) · 734 Bytes
/
V5.py
File metadata and controls
25 lines (21 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import math
def solve(a):
i, num = 0, 1
L = []
while i < a:
i = math.factorial(num)
L.append(i)
# If 'a' was just added to L, return its 1-based index right away
if a in L:
return L.index(a) + 1
num += 1
# If we exit the loop without finding 'a' in L, it's not a factorial
return -1
def brocard_problem_solver(start, end):
for number in range(start, end + 1):
x = number**2 - 1
result = solve(x)
# Check if 'solve(x)' gave a valid integer factorial index
if type(result) is int and result != -1:
print(f"{number} is a solution to Brocard's problem! (n! = {x}, n = {result})")
brocard_problem_solver(2, 10)