# How many $3$ digit numbers with digits $a$,$b$ and $c$ have $a=b+c$

My question is simple to state but (seemingly) hard to answer. How many $3$ digit numbers exist such that $1$ digit is the sum of the other $2$. I have no idea how to calculate this number, but I hope there is a simple way to calculate it. Thank you in advance.

EDIT: The first digit should not be $0$

• Make cases: $a=b=c=0$, $b=c\ne 0$ and $b\ne c$. For the last, order them ascending and multiply by $3!$ for permutations; for the former multiply by $3$. – AlexR Aug 7 '14 at 3:58
• If some such number is $abc$ then $a$ must be in $0, \ldots, 9$, so $b + c \in \{0, \ldots, 9\}$. Conversely if that's true, then you can just let $a = b + c$ and you get an integer of three digits. How many such $b, c$ are there? – Julien Clancy Aug 7 '14 at 4:01

Parameterize those numbers by $\overline {abc}$.

We have three cases, one when the first digit equals the sum of the other two. The second, when the second digit equals the sum of the other two, and so on...

## Case I

$\overline {abc}$, $a=b+c$

when $b$ is $0$, $c$ can be $\{1,2,...,9\}$

when $b$ is $1$, $c$ can be $\{0,1,2,3,...,8\}$ and so on...

$9+9+8+...+1=55-1=54$

## Case II

$\overline {bac}$, $a=b+c$

when $b$ is $1$, $c$ can be $\{0,1,...,8\}$

when $b$ is $2$, $c$ can be $\{0,1,...,7\}$ and so on...

Now, we've added some numbers here that we've also added in the previous case. Namely, the ones for which $b=a+c$ is true. Since we've added them in this case $b=a-c$ is also true, so $c$ must be $0$. $c$ is $0$ only when $b$ is $\{1,2,...,9\}$. So the final answer for this case is $45-9=36$.

## Case III

$\overline {bca}$, $a=b+c$

when $b$ is $1$, $c$ can be $\{0,1,...,8\}$

when $b$ is $2$, $c$ can be $\{0,1,...,7\}$ and so on..

Here we've added again some numbers, namely, for which $b$ is equal $a+c$, in step one. Note that we did not add any numbers that we added in case $2$ since, for those numbers we would have $c=b+a$(from case $2$) and also $c=a-b$(from step $3$). That would make $b$ $0$.(and we did not count that).

So, the final answer is $45-9=36$, for this case.

In total, we have $126$ numbers with that property.

Those numbers are: $$\begin{array}{|c|} \hline 101& 110& 112& 121& 123& 132& 134& 143& 145& 154& 156& 165& 167& 176& 178& 187&\\\hline 189& 198& 202& 211& 213& 220& 224& 231& 235& 242& 246& 253& 257& 264& 268& 275&\\\hline 279& 286& 297& 303& 312& 314& 321& 325& 330& 336& 341& 347& 352& 358& 363& 369&\\\hline 374& 385& 396& 404& 413& 415& 422& 426& 431& 437& 440& 448& 451& 459& 462& 473&\\\hline 484& 495& 505& 514& 516& 523& 527& 532& 538& 541& 549& 550& 561& 572& 583& 594&\\\hline 606& 615& 617& 624& 628& 633& 639& 642& 651& 660& 671& 682& 693& 707& 716& 718&\\\hline 725& 729& 734& 743& 752& 761& 770& 781& 792& 808& 817& 819& 826& 835& 844& 853&\\\hline 862& 871& 880& 891& 909& 918& 927& 936& 945& 954& 963& 972& 981& 990&\\\hline \end{array}$$

For verification, the code is:

 #include<iostream>

using namespace std;

int main() {
int q=0;
for(int a=1;a<=9;a++)
for(int b=0;b<=9;b++)
for(int c=0;c<=9;c++)
if(a==b+c || b==a+c || c==a+b)

{q++;cout<<a<<b<<c<<"\n";}

cout<<q; return 0; }


This, in case you do not allow $2-digit$ or $1-digit$ numbers.

One digit ($a$) will be at least as large or larger than the other two digits ($b, c$).   For every combination of $a$ and $b$ there can be only one value of $c$.

Another restaint is that the first digit cannot be 0, so we need consider the placement of the largest digit.

If the first digit is the largest, then we must count all pairs of of $a\in\{1,\ldots,9\}$ and $b\in\{0,\ldots, a\}$.

If the largest digit is the second or third digit then, as we have already counted all the cases when it is equal to another digit, we must count all pairs of $b\in\{1,\ldots,8\}$ and $a\in\{b+1,\ldots, 9\}$, twice (for the two placements).

The total count of is then: \begin{align} & =\sum\limits_{a=1}^9 \sum\limits_{b=0}^a 1 + 2\times \sum\limits_{b=1}^8 \sum\limits_{a-b=1}^{9-b} 1 \\ & = \sum\limits_{a=1}^9 (a+1) + 2\times \sum\limits_{b=1}^8 (9-b) \\ & = \tfrac{9(9+1)}{2} + 9 + 2(9\cdot 8 -\tfrac{8(8+1)}{2}) \\ & = 126 \end{align}

Various cases are: $$\begin{array}{|c|c|}\hline (a,b,c)|a+b=c&\text{total numbers}\\\hline (1,1,2),(2,2,4),...(4,4,8)&3!/2!\times4\\\hline (1,2,3)\text{ to }(1,8,9)&3!\times7\\ (2,3,5)\text{ to }(2,7,9)&3!\times5\\ (3,4,7)\text{ to }(3,6,9)&3!\times3\\ (4,5,9)&3!\times1\\\hline (1,0,1)\text{ to }(9,0,9)&2\times9\\\hline \end{array}$$ Total ways: $$3!/2!\times4+3!\times(1+3+5+7)+2\times9=12+6\times4^2+18=126$$

• missing that $0$ is a digit too ;) – AlexR Aug 7 '14 at 4:03
• And $(0,0,0)$ ;) – AlexR Aug 7 '14 at 4:06
• @AlexR do you think 000 is a three digit number? – RE60K Aug 7 '14 at 4:07
• Fun fact: allowing $000$ and $011$ etc. results in $1+12+123$ combinations. – AlexR Aug 7 '14 at 4:14
• Hey easy dude, control your tongue. if 1 was at the hundreth place and 0 at the tenth. Do you get a 3 digit number when you swap them? – MonK Aug 7 '14 at 5:44

My answer is similar to that of @shooting-squirrel. Edit: Now it gives the same answer, silly mistakes :D

Consider the number $\overline{abc}$, we have three cases:

Case 1: $a=b+c$, then $a$ can be $1,\dots,9$. Now, for each value of $a$, there are $a+1$ values of $b$: $0,1,\dots, a$. Each of which gives one number. Total numbers in this case is $$\sum^{9}_{a=1}(a+1)= \frac{(10+2)\cdot 9}{2}=54.$$

Case 2: $b=a+c$. Since $b\ge a$, $b$ can only be $1,\dots,9$. For each $b$, there are $b-1$ values of $a$: $1,\dots, b-1$. ($a=b$ was counted in Case 1).

Each of which gives one number. Total number in this case is $$\sum^9_{b=1}(b-1)=\frac{8\cdot 9}{2}=36.$$

Case 3: $c=a+b$. This case is similar to Case 2, with $c$ plays the role of $b$. So we have $36$ numbers in Case 3.

Total: Case 1 + Case 2 + Case 3 = $54+36+36=\color{red}{\mathbf{126}}$ numbers.

Assuming a digit is an element of $\{0,1,2,3,4,5,6,7,8,9,10\}$ we have three cases for $a,b,c$ to see:

1. $a=b=c=0$. All easy here, yields $1$ combination.
2. $b=c\ne 0$. $a=2b$, so $b<5$ giving us $4$ choices (digits $1$ to $4$). The position of $a$ uniquely determines the code, so multiply b $3$ to get $4\cdot 3 = 12$ combinations
3. $b\ne c$. We assume $a\ge b>c$ and chose $c$ first. Since $b+c < 10$ and $c<b$ $a \ge 2c$ so $c\le 4$. \begin{align*} c=4 & \Rightarrow b=5, a=9 & 1\\ c=3 & \Rightarrow b\in\{4,5,6\} & 3\\ c=2 & \Rightarrow b\in\{3,4,5,6,7\} & 5\\ c=1 & \Rightarrow b\in\{2,\ldots, 8\} & 7\\ c=0 & \Rightarrow b\in\{1,\ldots, 9\} & 9 (\text{only 2 distinct digits here}) \end{align*} totaling $16+9$ combinations, times $3! = 6$ for all but the $9$ we get $16\cdot 6 + 9 \cdot 3 = 123$

Summing up we have $1+12+123 = 136$ possibilities.

• How can 10 be a part of the set? – MonK Aug 7 '14 at 4:56
• @MonK see the discussion on Adityas' answer about that. – AlexR Aug 7 '14 at 4:57
• @AlexR,@MonK how can a single digit become double digit,i.e. 10 – RE60K Aug 7 '14 at 5:42
• @Aditya He probably shortened $010$... Whatsoever. – AlexR Aug 11 '14 at 12:59

For some, this might not be the most intuitive way, but it is a way to solve this problem.

If $a=b+c$, then if a is an even number it gives us 2 exceptions, and if a is odd it gives 1 exception. Will keep exceptions in a seperate bucket.

The maximum sum that can be reached is 9. So if $(b,c,a)$ represent the set of possible number then, $(1,8,9),(2,7,9),(3,6,9),(4,5,9)$ and then $b,c$ change place. That's $4\times 2 =8$ numbers. And since places are not fixed, therefore its $8\times3=24$ numbers + 1 exception $(909)$

Now, For 8 $(1,7,8),(2,6,8),(3,5,8)$ that's $3\times2\times3=18$ numbers +2 exceptions $(448,808)$

For 7 $(1,6,7),(2,5,7),(3,4,7)$ that's $3\times2\times3=18$ numbers +1 exception $(707)$

For 6 $(1,5,6),(2,4,6)$ that's $2\times2\times3=12$ numbers +2 exception $(606,336)$

For 5 $(1,4,5),(2,3,5)$ that's $2\times2\times3=12$ numbers +1 exception $(505)$

For 4 $(1,3,4)$ that's $2\times1\times3=6$ numbers +2 exception $(404,224)$

For 3 $(1,2,3)$ that's $2\times1\times3=6$ numbers +1 exception $(303)$

So far, 96 numbers. Now, lets look at the combinations of number put in exception and will count and add seperately. $(909,990,448,844,484,808,880,707,770,606,660,336,363,633,112,121,211,202,220,101,110)$

Total count of number :$117$

• I've checked with the computer... Please see my answer. The answer 109 is wrong. – shooting-squirrel Aug 7 '14 at 5:33
• I think I counted the numbers just right, can you highlight an example I might not have included? – MonK Aug 7 '14 at 5:40
• caught my mistake hang on. – MonK Aug 7 '14 at 5:45