8
$\begingroup$

Find all $\{ m, n \} \in \mathbb{Z}^+$ such that

$$\sum\limits_{k=1}^m k! = n^2 .$$

The two solutions are $\{ m,n \} = \{ 1,1 \}$ and $\{ 3,3 \}$, as can be confirmed. Here is how to solve this problem mathematically. I seek to solve it using computer symbol manipulation (and preferably not through exhaustive search.)

The obvious approaches do not work:

Solve[Sum[k!, {k,1,m}] == n^2 && {m, n} > 0, {m, n}, Integers]

and

FindInstance[Sum[k!, {k,1,m}] == n^2 && {m, n} > 0, {m, n}, Integers]

Any suggestions?

$\endgroup$
7
  • $\begingroup$ Ask it at MSE. This is rather math than Mathematica. $\endgroup$
    – user64494
    Aug 6, 2021 at 18:55
  • $\begingroup$ I know how to solve it mathematically. (Michael Penn solved it on his Youtube channel.) I want to know how to do it in Mathematica. $\endgroup$ Aug 6, 2021 at 19:00
  • $\begingroup$ In each of your Sums, the summand should be k! vice n!. However, that does not resolve the issue. A brute force approach: Select[Flatten[Table[{m, n}, {m, 1, 100}, {n, 1, 100}], 1], Sum[k!, {k, 1, #[[1]]}] == #[[2]]^2 &] $\endgroup$
    – Bob Hanlon
    Aug 6, 2021 at 19:03
  • 1
    $\begingroup$ The command FindInstance[Sum[k!, {k, 1, m}] == n^2 && {m, n} > 0, {m, n}] results in {{m -> 1, n -> 1}}. $\endgroup$
    – user64494
    Aug 7, 2021 at 7:38
  • 1
    $\begingroup$ Solve, Reduce. Minimize, and FindMinimum all promptly convert Sum[k!, {k,1,m}] to -1 - Subfactorial[-1] + (-1)^(1 + m) Gamma[2 + m] Subfactorial[-2 - m], which apparently is correct. However, if the Reals or Integers domains are specified, these functions eventually realize that Subfactorial[-1] is complex and quit with an error message. I view this as a bug, because this internal error should not leak out. In fact, it occurs even for the trivial SolveValues[Sum[k!, {k, 1, m}] == n, n, Reals]. $\endgroup$
    – bbgodfrey
    Aug 7, 2021 at 13:26

2 Answers 2

2
$\begingroup$

Check the QuadraticResidues resource function https://resources.wolframcloud.com/FunctionRepository/resources/QuadraticResidues/

QuadraticResidues[5]
(* {0, 1, 4} *)

Thus, 3 is the quadratic nonresidue (mod 5).

Next, observe that this comes at contradiction with the property of the LHS for $m>4$:

f[m_] := Sum[k!, {k, 1, m}]
Table[Mod[f[m], 5], {m, 15}]
(* {1, 3, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3} *)

This fact is easy to see from $n!=0\,(\text{mod}\, 5)$ for $n\ge5$.

Thus, the only possibility $m=1$ and $m=3$. Now solve the equation

Solve[f[1] == n^2 && n > 0, n, Integers]
Solve[f[3] == n^2 && n > 0, n, Integers]

Notice that for completely automatic solution it is necessary that MA "knows" quadratic residues in some simple cases. Currently besides the resource function, this in not available.

$\endgroup$
2
  • $\begingroup$ Wow... I never would have come across that clever approach on my own. Thanks so much. ($+1$). Actually, because this is the most symbolic approach: $\checkmark$. $\endgroup$ Aug 8, 2021 at 16:20
  • $\begingroup$ @DavidG.Stork Thank you! Really appreciate. $\endgroup$
    – yarchik
    Aug 8, 2021 at 16:47
2
$\begingroup$

Numerical solution with NMinimize / NMaximize .

su[m_?NumericQ] := NSum[k!, {k, 1, m}, NSumTerms -> m]

nmin = NMinimize[{n, {m >= 1, m \[Element] Integers, n >= 1, 
n \[Element] Integers, (su[m] - n^2) == 0}}, {m, n}]

(*   {1., {m -> 1, n -> 1}}   *)

nmax = NMaximize[{n, {m >= 1, m \[Element] Integers, n >= 1, 
n \[Element] Integers, (su[m] - n^2) == 0}}, {m, n}]

(*   {3., {m -> 3, n -> 3}}   *)
$\endgroup$
1
  • $\begingroup$ Interesting approach... I certainly hadn't thought of that. Thanks. ($+1$) $\endgroup$ Aug 8, 2021 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.