What is the smallest number which consists of the digits 1 through 9 exactly once and is divisible by 99?
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.
Yea, the divisibility by 11 is the tricky part. Even after identifying what must be done, there are still various arguments that need to be made in order to minimize the final value that we obtain.
I did the same too
You know that the sum of digits is going to be 45, and so there are only a few ways to do the divisibility test for 11(since it's always going to be divisible by 9). To get odds-evens to be 11, sum of odds must be equal to 28, it's impossible to get odds-evens=0. There are very few combinations to get odds sum of 28, and one of them is the answer. I know that this is not a solution but it's some insight.
What trickery is this? They title SPECIFICALLY says "from 1 (...) to 99" and the answer is f ** 123475769? Are you mocking us? The problem is bloody impossible if the answer is between 1 and 99. Stop inventing pretty and original names and either give a RELEVANT title or NO title at all. Ugh... I'm so mad at this...
Log in to reply
Thanks for your feedback. I have removed the title "From 1 to 9 to 99" since there are possible misinterpretations of what it means.
Please be respectful of the community when typing comments.
Log in to reply
Sometimes when one tries to be too clever, there's blowback, huh? I guess the movie, "From Here to Eternity" has gotten some viewers angry because it never got to eternity.
Question could have better be asked as:What is the smallest number consists of 9 distinct digits and containing each of 1 to 9 exactly once?
Wow, harsh!
you are totally right, harsh thou. I really didn't understand the problem too!
Relevant wiki: Divisibility Rules (2,3,5,7,11,13,17,19,...)
As the numbers 9 and 1 1 are coprime, we can say that n is divisible by 9 9 iff it's divisible both by 9 and 1 1 . As all the numbers consisting digits 1 through 9 exactly once are divisible by 9 (because the sum of the digits is divisible by 9 ), we are looking for the smallest n consisting each digit exactly once and being divisible by 1 1 .
Let's denote the odd position digits of n by A and even position digits by B such as n = ( A 1 B 1 A 2 B 2 A 3 B 3 A 4 B 4 A 5 ) .
The divisibility rule for 1 1 tells us that ∑ A − ∑ B ≡ 0 ( m o d 1 1 ) . Because the divisibility does not depend on the order of digits within A and within B , the immediate conclusion from the minimality constraint for n is that A 1 < A 2 < A 3 < A 4 < A 5 and B 1 < B 2 < B 3 < B 4 .
Because ∑ A + ∑ B = 4 5 , we can rewrite the congruent equation as ( 4 5 − ∑ B ) − ∑ B ≡ 0 . This gives us 2 ∑ B ≡ 1 and ∑ B ≡ 6 ( m o d 1 1 ) .
Also we have: 1 0 = 1 + 2 + 3 + 4 ⩽ ∑ B ⩽ 6 + 7 + 8 + 9 = 3 0 and this with the congruent equation gives us two solutions: ∑ B = 1 7 or ∑ B = 2 8 .
Let's look at the solutions where n starts with 1 2 3 4 . We have ( B 1 , B 2 ) = ( 2 , 4 ) . If ∑ B = 2 8 then B 3 + B 4 = 2 2 and there are no solutions amongst single digits.
If ∑ B = 1 7 then we have B 3 + B 4 = 1 1 (and of course 4 < B 3 < B 4 < 9 ). This gives us the only solution B = ( 2 , 4 , 5 , 6 ) and the final solution n = 1 2 3 4 7 5 8 6 9 .
We have found the only solution starting with the digits 1 2 3 4 , thus we can conclude it's the minimal one.
Beautiful solution!
I'm really sorry, I thought this was a Computer Science problem. Though I got how to do it manually, here's the Python code anyway.
import itertools
string = "123456789"
numbers = [int("".join(x)) for x in itertools.permutations(string) if int("".join(x))%99==0]
numbers.sort()
print numbers[0]
We could also say:
print min(int("".join(x)) for x in itertools.permutations(string) if int("".join(x))%99==0)
Please change the word usage, I did not know that I have to use all the digits from 1 to 9 >_<
Problem Loading...
Note Loading...
Set Loading...
First, since the sum of the digits from 1 to 9 is divisible by 9 , any permutation is divisible by 9 , so we only need to look at divisibility by 1 1 . A well known digit test for that is do an alternating sum of the digits, which , if divisible by 1 1 , will mean that the number itself is also divisible by 1 1 . So, we start with the smallest possible number and check this sum
1 − 2 + 3 − 4 + 5 − 6 + 7 − 8 + 9 = 5
which means it's not divisible by 1 1 , and we need to make the sum divisible by 1 1 . We can change the sum only by transposing some of the digits, and they need to be of a different sign to make a difference. However, the difference in the sum will always be an even number, so it's pointless to do transposes that reduces the sum (can't get from 5 to 0 ), so we look for transposes that raises it. We focus on the digits to the far right. We transpose the furthest right digits that will do the job immediately
1 − 2 + 3 − 4 + 8 − 6 + 7 − 5 + 9 = 1 1
and then we rearrange to get the smallest possible number (sort them in each sign group)
1 − 2 + 3 − 4 + 7 − 5 + 8 − 6 + 9 = 1 1
Thus we end up with 1 2 3 4 7 5 8 6 9 which is divisible by 9 9 .