Overview
Brocard's Problem Explorer searches for solutions to the equation n! + 1 = m², where n! is the factorial of n and m is an integer. All factorial and square calculations are performed using Romasm assembly.
Brocard's Problem
What is it?
Brocard's Problem asks: For which positive integers n does the equation
n! + 1 = m²
have integer solutions?
Known solutions:
- n=4: 4! + 1 = 24 + 1 = 25 = 5²
- n=5: 5! + 1 = 120 + 1 = 121 = 11²
- n=7: 7! + 1 = 5040 + 1 = 5041 = 71²
Status: Only three solutions are known. It is unknown if there are more.
Romasm Implementation
The explorer uses Romasm assembly to calculate factorials and check for perfect squares:
; Check if n! + 1 is a perfect square
; Input: R0 = n
; Output: R0 = m if solution found, 0 if not
; Calculate n!
CALL factorial ; R0 = n!
; Add 1
INC R0 ; R0 = n! + 1
; Check if it's a perfect square
; Calculate sqrt(n! + 1)
CALL sqrt ; R0 = sqrt(n! + 1)
; Square it back to verify
LOAD R1, R0
MUL R1, R0 ; R1 = (sqrt(n! + 1))²
; Compare with original
LOAD R2, R0 ; R2 = n! + 1
CMP R1, R2
JEQ found_solution
; Not a perfect square
LOAD R0, 0
RET
found_solution:
; R0 already contains sqrt(n! + 1) = m
RET
Using the Explorer
- Enter a value for n (or let it search automatically)
- Click "Search for Solution"
- View the calculated n! + 1
- See if it's a perfect square and find m
Related Documentation
- Math Library - Factorial and square root functions
- Try the Explorer - Open it now!