What three-digit integer is equal to the sum of the factorials of its digits?

6.9k Views Asked by At

This question that is stated in the title is giving me quite a bit of trouble. Some help understanding how to solve the problem would be immensely appreciated.

Thanks ^_^

7

There are 7 best solutions below

1
On

$145=1!+4!+5!$. There may be other solutions ?

0
On

This ought to get you started: The largest digit is clearly either $5$ or $6$, since that's the only way to make the sum three-digit. $6$ can be ruled out pretty easily, since any number larger than $6!$ has either a $7,8$ or a $9$ in the hundreds digit.

So the largest digit is $5$. There aren't too many options left to test. Try it out, and see what works.

0
On

Assuming a decimal number system, a three digit integer with digits $a, b, c$ is the number:

$$100a + 10b + c$$

So the equation to solve is:

$$100a + 10b + c = a! + b! + c!$$

Now, I would tackle this with a combination of brute force and clever pruning of the search space. I'll just give you a hint to get started. The number cannot exceed $999$, right? Now, on the right hand side of the equation are three factorials, all positive, so none of these can exceed $999$ either. However:

$$9! > 8! > 7! > 999$$

So you immediately rule out $9, 8, 7$ as possible candidates for the digits!

EDIT: wythagoras has far surpassed this reasoning in a very concise answer that beautifully hones in on the solution.

0
On

Some observations that you can transform into a solution:

  • Such a number cannot contain a digit $7, 8$ or $9$, since the number then becomes too large.
  • If it contains a $6$, it must be at least $720$, so then the first digit is too large.
  • If it does not contain a $5$, the sum of the factorials is at most $72$. So it contains a $5$.
  • The number is at most $360$, but that can only happen with three fives. So it is at most $2 \cdot 5! +4! = 264$. So the first digit is a one or a two.
  • Now consider cases. If the first digit is a $2$, there must be two fives, so $255$. This isn't a solution. If the first digit is a one, we get either $105+10n = 121+n!$ or $150+n = 121+n!$. From this, we can just check possibilities for $n$ and see that $145=1!+4!+5!$ is the only solution.
0
On

Since $abc$ is at most $999$ we have $a,b,c\leq 6$, but then $abc\leq 666$, so $a,b,c\leq 5$. But now $a!+b!+c! \leq 360$ so $a\leq 3$ and thus $a!+b!+c!\leq 246$ so $a\leq 2$ and now $a!+b!+c!\leq 242$.

So if $a=2$ then $a!+b!+c!\leq 2+24 +120 < 200$ which is impossible.

If $a=1$ then we get $a!+b!+c!\leq 199$ so if $b\leq 4$ and $c\leq 4$ we get $a!+b!+c!\leq 49$ impossible. So $b=5$ or $c=5$ ...

0
On

Let $a$, $b$, and $c$ be the digits of this number, all of which are in $\{1, \dots, 9\}$ (and $c$ may be $0$ as well).

Then $10^3 a + 10^2 b + 10c = a!+b!+c!$ describes all numbers which satisfy your given condition.

Simulating this in R:

for (a in 1:9) {
  for (b in 1:9) {
    for (c in 0:9) {
      n <- factorial(a) + factorial(b) + factorial(c)
      if (nchar(n) == 3 & as.numeric(substr(n, start = 1, stop = 1)) == 
        a & as.numeric(substr(n, start = 2, stop = 2)) == b & as.numeric(substr(n, 
        start = 3, stop = 3)) == c) {
        print(n)
      }
    }
  }
}
#> [1] 145

Thus, 145 is the only solution.

0
On

We first see that we can only use the digits $0$ through $5$. Why? Because $9! > 8! > 7! = 5040 >= 1000$. We cannot use $6$ because $6! = 720$, which means the hundreds-digit must be $7$, $8$, or $9$, which are not allowed. We see that $5$ is necessary - because if $5$ was not in the number, then the largest sum of factorials is $4! + 4! + 4! = 72 < 100$. We see that the largest number that we can form by the sum of factorials is $5! + 5! + 5! = 360$, so only $1$, $2$, or $3$ can be in the hundreds place. $3$ cannot be in the hundreds place because $355$ forms $6 + 120 + 120 = 246 < 300$ is the largest sum of factorials you can make. $2$ cannot be in the hundreds place because $254$ makes $2 + 120 + 24 = 146 < 200$ and $255$ makes $244$, which does not match. Now you know $1$ is in the hundreds place. From here, you only need to check ten cases:

$105$,

$115$,

$125$,

$135$,

$145$,

$150$,

$151$,

$152$,

$153$,

$154$

Of these, only $145$ works.

EDIT:

I realized you can simplify this much more by noticing that rearranging the numbers doesn't matter. Then check only $1! + 0! + 5! = 121$ does not work. $1! + 1! + 5! = 122$ does not work. $1! + 2! + 5! = 123$ does not work. $1! + 3! + 5! = 127$ does not work. $1! + 4! + 5! = 145$ does work. $1! + 5! + 5! = 241$ does not work, and you are done. The only match is $145$.