conjecscore
Login Sign up

Leaderboard

deeply_dreaming
11
InhaleWins
11
liuguangxi
11
thyrgle
1938
ZamoC
1938
1434
4591
Nondegon
199501246

Brocard's Problem

The Problem

When \(n \geq 8\) is it ever the case that \(n! + 1\) is a perfect square?

Submission Format

Please submit a CSV file that contains \(1\) number. This number corresponds to \(n\). Let \(m = \lfloor \sqrt{n! + 1} \rfloor\) and \(M = \lceil \sqrt{n! + 1} \rceil\). Then the score is computed as: $$\frac{\min\{n! + 1 - m^2, M^2 - n! - 1\}}{M^2 - m^2} \times 10^9$$ The goal is to minimize this score function.

Score Implementation

The following is a Python implementation of the score function to help you get started.


from math import factorial, isqrt


def score(nums: list[int]):
    # Ensure only one number is supplied.
    if len(nums) != 1:
        return None
    # Ensure numbers are positive.
    num = nums[0]
    if num <= 0:
        return None
    
    nfact = factorial(num) + 1
    sml_sqrt = isqrt(factorial(num) + 1)
    big_sqr = (sml_sqrt + 1) ** 2
    sml_sqr = sml_sqrt ** 2 # Now square!
    interval = big_sqr - sml_sqr
    return int((min(nfact - sml_sqr, big_sqr - nfact) / interval) * 10 ** 9)