How many five-digit palindromes are divisible by 1 3 5 ?
58185
58185 ÷ 1 3 5 = 4 3 1
- Note: A five-digit number cannot start with 0.
- Inspiration: This daily challenge
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
similar solution
The divisibility rule for 1 3 5 = 5 × 2 7 , must include the divisibility rules of 5 and 2 7 .
Any number must end in 5 , 0 . It must end with 5 because if it is 0 , the leading digit will also be a 0 thus making it a four-digit number. So, the palindrome is of the form: 5aba5
The sum of its digits must be divisible by 2 7 . The maximum digit sum of any 5-digit number can be 4 5 < 2 7 ( 2 ) , thus:
5+a+b+a+5 = 2 7 2a + b = 1 7
We know that ( a , b ) are single digit numbers, thus it is easy to enumerate all of the solutions
a a a a a a a a a a = 0 ⟹ b = 1 7 = 1 ⟹ b = 1 5 = 3 ⟹ b = 1 1 = 2 ⟹ b = 1 3 = 4 ⟹ b = 9 = 5 ⟹ b = 7 = 6 ⟹ b = 5 = 7 ⟹ b = 3 = 8 ⟹ b = 1 = 9 ⟹ b = − 1 [Not accepted] [Not accepted] [Not accepted] [Not accepted] [Accepted] [Accepted] [Accepted] [Accepted] [Accepted] [Not accepted]
Thus we see that there are: 5 solutions
@Mahdi Raza , how can I write solution where the code looks like in the Daily Challenge solutions of some people? I mean, how can the Python interface be pasted here? Thanks!
Log in to reply
Look formatting guide
add ``` at the beginning and end of the code snippet after simply pasting it in the answer NOTE: the symbol is not the single quotation mark ' its another symbol forgot what it's called, for me, this is at the top left under the escape key
We note that the multiples of 1 3 5 can either end with 0 or 5 . But ending with 0 is not acceptable because then the five-digit palindrome will start with 0 . Therefore the required palindrome multiples of 1 3 5 must end with 5 and start with 5 . That it is of the form 5 a b a 5 . Since 1 3 5 is divisible by 9 , 5 a b a 5 must also be divisible by 9 and its sum of digits ( 1 0 + 2 a + b is also divisible by 9 . That is 2 a + b = 8 , 1 7 , or 2 6 . Now we have 5 a b a 5 = 5 0 0 0 5 + 1 0 1 0 a + 1 0 0 b = 5 0 0 0 5 + 8 1 0 a + 1 0 0 ( 2 a + b ) Since 1 3 5 = 5 × 2 7 , ,
5 5 a b a 5 1 0 0 0 1 + 1 6 2 a + 2 0 ( 2 a + b ) 1 1 + 2 0 ( 2 a + b ) ≡ 0 (mod 27) ≡ 0 (mod 27) ≡ 0 (mod 27)
Consider the three cases of 2 a + b , if 2 a + b = ⎩ ⎪ ⎨ ⎪ ⎧ 8 1 7 2 6 ⟹ 1 1 + 2 0 ( 8 ) ≡ 9 (mod 27) ⟹ 1 1 + 2 0 ( 1 7 ) ≡ 0 (mod 27) ⟹ 1 1 + 2 0 ( 2 6 ) ≡ 1 8 (mod 27)
Therefore there are solutions only when 2 a + b = 1 7 and the palindrome 1 3 5 -multiples are ⎩ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ ⎧ 5 4 9 4 5 5 5 7 5 5 5 6 5 6 5 5 7 3 7 5 5 8 1 8 5 , altogether 5 .
My Python code solution:
ohh interesting you worked through it backwards in your python code Brilliant as this website is called XD.
1 2 3 4 5 6 7 8 |
|
result
1 2 3 4 5 6 |
|
1 2 3 4 5 6 |
|
Problem Loading...
Note Loading...
Set Loading...
Code:
Output: