# combinatorics and divisibilty

in how many ways we can form a $8$ digit numbers from $1,2,3,4,5$ with repetition allowed & divisible by $8$.

MY APPROACH :

to be divisible by 8 : last 3 digit of the no. must be divisible by 8 like $152 , 112$(as repetition allowed),.......[ let total no. of these 3 digit numbers are x ]

then total ways of other 5 diigit = 5^5

now for each way of first 5^5 combinations there will be further x combination for last three

so it becomes (5^5) $*$ (x^5)

is it correct???i dont think it is correct???how to solve it???

• You need to figure out what $x$ is. Then you have $5^5$ choices for the first 5 digits, and $x$ choices for the last three, so your total is $5^5\cdot x$. Mar 1, 2014 at 19:54
• is there aby quick method to find x??? Mar 1, 2014 at 19:56
• is 5^5 * x correct answer??? Mar 1, 2014 at 19:57
• Yes, I just said that. To find $x$, first note that the last digit must be a 2 or a 4. Then you can exhaust the 50 choices that remain pretty easily. Mar 1, 2014 at 19:57
• @RitabrataGautam: Do you mean that for a number (with more than 3 digits) in general to be divisible by $8$ its last three digits must add to a multiple of $8$? How about 144; 1+4+4=9? Mar 1, 2014 at 20:29

A number is divisible by $8$ if the last three digits are divisible by $8$.

Now, we can arrange the first $5$ digits of our answer in $5^5$ ways, because each of the position can take $1$ of $5$ values.

Now, our problem reduces to the following.

How many three digit numbers formed with $\{1,2,3,4,5\}$ are divisible by $8$? We can enumerate all the possibilities, preferably in a programming language. In Python,

acc = 0
for x in range(1,6):
for y in range(1,6):
for z in range(1,6):
if int(str(x)+str(y)+str(z))%8 == 0: acc += 1

print acc


This yields an output of $13$. The favourable numbers are

112
144
152
224
232
312
344
352
424
432
512
544
552


Thus, since the last three digits can take any of these $13$ values, and the first five digits can take $5^5$ values, our final answer is $5^5 \times 13 = \boxed{40625}$

Of all the numbers that are formed with 1,2,3,4,5 - the last three digits need to be divisible

by 8. There are 5^3 ways you could arrange the five numbers for the last three digits. Of

these last three digits that are divisible by 8 are 312, 152, 512, 432, 352, 112, 232, 224,

144, 424, 344, 552, 544. A total of 13 of them which I got by brute force in EXCEL by writing

a small program. Divisibility by 8 is the screwist one.

With these as the last three digits with the first five from {1,2,3,4,5}. The total number of ways then will be $13*5^5$

The answer is $13*5^5$