How many 8-digit palindromic numbers are composite (i.e. not prime)?
Details and Assumptions:
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.
Why do we multiply nine with 10^3?
Log in to reply
Because b,c and d can be any of the 10 digits, and they are independent. Or, look at it differently: we are looking for all the 4 digit positive integers, and there are 9000 of them.
Where do you get that divisibility rule for 11 from?
Log in to reply
It is fairly well-known. It is based on the fact that 1 0 ≡ − 1 mod 11, so 1 0 n ≡ ( − 1 ) n . More explicitly,
1 0 n = ( 1 1 − 1 ) n = 1 1 k + ( − 1 ) n .
Therefore, when it comes to remainders after division by 11, the n th digit behaves as if its place value were either + 1 or − 1 .
good to know that divisibility rule, with a longer route I noticed that calling z k = 1 0 1 + 2 k + 1 , then 1 1 z k = 1 + 9 ( 1 0 + . . . + 1 0 2 k − 1 ) so a ∗ z 3 + b ∗ 1 0 ∗ z 2 + c ∗ 1 0 2 ∗ z 1 + d ∗ 1 0 3 ∗ z 0 is also divisible for 11
I did not make the assumption that a number could not start with a leading zero. I'm not sure why that would be a given.
Log in to reply
It is a convention worldwide not to write leading zeroes.
Log in to reply
But 'not write' doesn't mean that it isn't legit for a number. Mostly you leave it off and just have a space. I guess it would have been nice to have it explicitly stated. 03 depending on convention is conventionally equal to decimal 3 or octal 3 'worldwide'.
Log in to reply
@Kurt Schwind – I'll add a note in the problem.
Because the question explicitly states that a leading zero in the 8 digit number is not a "valid 8-digit palindrome".
Wait...don't we have to eliminate every prime number in that 9 10 10*10 series of numbers?
Log in to reply
It can't be a prime number as it's divisible by 11
..howagain is any palindrome divisible by 11? I overthought the $#!t outta this
Log in to reply
Only palindromes of even length. Note, for instance, that all of 0 0 0 1 1 0 0 0 , 0 0 1 1 1 1 0 0 , 0 1 1 1 1 1 1 0 , 1 1 1 1 1 1 1 1 are obviously multiples of 11. Now a b c d d c b a = 1 1 1 1 1 1 1 1 a + 0 1 1 1 1 1 1 0 ( b − a ) + 0 0 1 1 1 1 0 0 ( c − b ) + 0 0 0 1 1 0 0 0 ( d − c ) .
What other rules are there for divisibility? Obviously 5^n and 2^n divisibility is checked by the divisibility of the last n digits. 3 divisibilty is checked by the the divisibility of the sum of the digits. The 11 is tested by the divisibility of the difference of the sums of the odd and even placed digits. Anymore short-cuts?
This question would be a lot harder if it weren't multiple choice as a lot of the choices can be eliminated.
Let's call an 8 digit palindrome a b c d d c b a .
Since every digit, except a which can't be 0 , can be the digits ( 0 , 1 , 2 , ⋯ 8 , 9 ) therefore there are 1 0 × 1 0 × 1 0 × 9 = 9 0 0 0 different possibilities for the number a b c d d c b a . So we can eliminate the first choice. Also the 8 digit palindrome is definitely composite if a is even. This means that 1 0 × 1 0 × 1 0 × 4 = 4 0 0 0 so we can eliminate choice 2 and choice 3.
∴ The answer is choice 4 9 0 0 0 .
Actually, all palindromes with an even number of digits are divisible by 1 1 (see the divisibility rules). Thus, all eight-digit palindromes are composite numbers.
Log in to reply
That's a good point. I did not know this. Thanks
It seems someone took this under advisement: as of just now when I solved it, it was not multiple choice (mobile app, so ymmv)
Really... it isnt a multiple choice question... But i understood the sol
If the number of digits is even then all palindromes are not primes since they are divisible by 11 (sure, with one exception of 11 for two-digit number).
Also, if the number of digits is odd it's harder to come up with the correct answer. In that case, the following procedure could be used:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
For different n it returns:
n | # composite palindromes |
1 | 5 |
2 | 8 |
3 | 75 |
4 | 90 |
5 | 807 |
6 | 900 |
7 | 8332 |
8 | 9000 |
I feel you should start n at 2 in your program. 1 digit palindromes aren't really a thing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
1 2 |
|
My methode was to considre that there are 4 digits identical to the other 4 digits so we have 9999 case : a b c d ' d c b a but we must eliminate all numbers which start with 0 , in 10 we have only 1 number starts with 0 which is 10 in 100 we have 10 so in 10000 we have 999 number ( don't add 10000 as a case) so we got 9999 cases substracted by 999 and in the end we had 9000
@Haroun Khoualdia , good solution :)
Every 8 digit palindrome d 1 d 2 d 3 d 4 d 4 d 3 d 2 d 1 can be written as:
d 1 ( 1 0 7 ) + d 2 ( 1 0 6 ) + d 3 ( 1 0 5 ) + d 4 ( 1 0 4 ) + d 4 ( 1 0 3 ) + d 3 ( 1 0 2 ) + d 2 ( 1 0 1 ) + d 1 ( 1 0 0 ) = d 1 ( 1 0 0 0 0 0 0 1 ) + d 2 ( 1 0 0 0 0 1 0 ) + d 3 ( 1 0 0 1 0 0 ) + d 4 ( 1 1 0 0 0 )
And , since 10000001, 1000010, 100100, 11000 all pass the divisible rule of 11 (the difference of the alternating sum of digits of N is a multiple of 11):
all 8-palindrome is a factor of 11; a composite number.
So the aswer is all posible 8-palindromes: 9 ⋅ 1 0 3
First one is 1000 0001, last one 9999 9999, there is 9000 number between 1000 and 9999
Since C is a fast language, I decided to use it for the purposes of this question. It runs pretty well, in about 4 seconds on my machine:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
This yields the result 9000 .
In any number if we add alternate digits and subtract one from the other, like for example if a number is 'abcd' sum of alternate digits is a+c, b+d. If the difference is divisible by 11, then the number is divisible by 11.
So any palindrome of even size, like aa, abba, abcddcba, etc will all be divisible by 11 as the difference of sum of alternate digits is 0.
So every palindrome is composite. As first number can't be a 0, we can have 9 different digits to choose from for the first digit. Three following digits can take any of 10 numbers 0-9. The rest 4 are the first 4 in reverse order.
Total composite palindromes =9 10 10*10 =9000
There are 8 digits abcdefgh .In this number a=h, b=g, c=f, d=e. Then the number comes out to be abcddcba. 'a' can have only 9 values , 'b' an have 10 values , 'c' can have 10 values and 'd' can also have 10 values . Rest of digit. must have same value as a,b,c,d so they can take only one value. So the answer is 9x10x10x10x1x1x1x1 = 9000 .
And every palidromic number which contains even number of digits is multiple of 11. abcdefgh : ( a+c+e+g)-(b+d+f+h)=(a+b+c+d)-(a+b+c+d). { a=h,b=g,c=f,d=e}
=0,
Which means that is divisible by 11
It's the answer to the other question: "How many 8-digit palindromic numbers exists?", nothing about primes and composites.
Why is the answer to this question 9000, when the number of decimal palindromic numbers of 8 digits, as given on Wikipedia etc, is 19999 ?
Ref: https://en.wikipedia.org/wiki/Palindromic_number
and
Ref: https://oeis.org/A070199
Log in to reply
But are they are composite numbers?
Log in to reply
There are no 8-digit palindromic numbers which are prime, so all of them are composite. This takes me back to my confusion as to why the sources I provided seem to indicate that there are 19999 of them rather than 9000? Who is correct, and why is there a discrepancy?
Log in to reply
@Nicholas Lee – What are you talking about prime and composite, I am not getting it. You just see that first digit can take 9 value, second 10, third and fourth also 10, and rest has Fixed value so they can take only one value. So answer must be multiplication of 9,10,10,10,1,1,1,1 = 9000
Log in to reply
@Suresh Jh – Did you ever read the question in the task? "How many 8-digit palindromic numbers are composite (i.e. not prime)? " And yes, both questions have "9000" as the answer, but it doesn't allow you not to mention that all of these palindroms are composites.
Log in to reply
@Андрей Фасалов – Hey, I got it. I want to note that every palidromic number with even number of digits is multiple of 11. You can check..
Log in to reply
@Suresh Jh – Then maybe it should be in your solution? Otherwise, it's incomplete.
Log in to reply
@Андрей Фасалов – Yes, it's in my solution
Log in to reply
@Suresh Jh – Are you making fun of me? There is no word about divisibility in your solution. Maybe I'm blind? Would you please show a moment where you say that all of this palindromes are divisible by 11? There are 8 digits abcdefgh .In this number a=h, b=g, c=f, d=e. Then the number comes out to be abcddcba. 'a' can have only 9 values , 'b' an have 10 values , 'c' can have 10 values and 'd' can also have 10 values . Rest of digit. must have same value as a,b,c,d so they can take only one value. So the answer is 9x10x10x10x1x1x1x1 = 9000
Log in to reply
@Андрей Фасалов – No, I'm not making your fun. I forget to note it in the solution. Now I have edited it.
@Nicholas Lee – Ha, I spotted the difference! The https://oeis.org/A070199 page was giving the number of of palindromes of length <= n, rather than the number of of palindromes of length n That's why they gave 19999 as the total, rather than 9000.
abcddcba
a : 1 to 9 = 9 digit
b : 0 to 9 = 10 digit
c : 0 to 9 = 10 digit
d : 0 to 9 = 10 digit
(9) (10) (10)*(10) = 9000 numbers
We don't need to consider the last 4 digits of it which is symmetric. But 0 is not allowed at the first. We can choose 1 to 9 at the first digit, and second to fourth would be 10 choices. And these occurs simultaneously that we multiply 4 of them: 9•10^3=9000
1 2 3 4 5 6 7 8 9 10 11 |
|
Any even digit palindrome is always composite only(always multiple of 1 1 )
So for ( 2 n ) digit palindrome, the answer is
9 ( 1 0 n − 1 )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
The answer is 9 0 0 0 Of course you can check whether s is divisible by primes greater than 13. You will find no change
Solution not knowing the 'division by 11 rule' and using R-script
The inner 6 numbers of the palindrome are constructed using the numbers 000:999 and for each one we paste its mirror behind it. (ex: 001 100). This leads to a total of 1000 numbers of length 6.
What we know for the outer numbers (first and last) of the palindrome:
Palindromes starting/ending with 0 are not allowed
Palindromes starting/ending with an even number are guaranteed composite (n = 4 x 1000)
Palindromes starting/ending with 5 are guaranteed composite (n = 1 x 1000)
==> We have at least 5000 composite palindromes
This leaves us with 4000 numbers to check: the ones starting/ending in 1, 3, 7, 9. We can use a script to check each number.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
The script runs in less than a second and returns 0 prime numbers, so all 4000 are composite. This means in total there are 5000 + 4000 = 9000 composite palindromes of length 8
I did:
1 2 3 4 5 6 7 8 9 10 11 |
|
I solved this with ruby...
require 'prime'
a=0
for i in 1..9
for j in 0..9
for k in 0..9
for l in 0..9
if not(Prime.prime?(i*10000001+j*1000010+k*100100+l*11000))
a+=1
end
end
end
end
end
puts a
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
I'm not a good programmer and this takes an insane amount of time, but it worked. Also, I can't figure out how to format this so it becomes readable, sorry.
Problem Loading...
Note Loading...
Set Loading...
The key is that any 8-digit palindrome is composite, because it is a multiple of 11. This follows most easily from the divisibility rule for 11: a b c d d c b a is divisible by 11 iff a − b + c − d + d − c + b − a = 0 is divisible by 11 , which is obviously the case.
The problem is now reduced to counting how many such palindromes there are. For b , c , d we have 10 digits to choose from; for a only 9, because a number can't start in zero. This leaves us with 9 ⋅ 1 0 3 = 9 0 0 0 palindromes.