Good to Solve INMO problem

All possible 6-digit number, in each of which the digits occur in non-increasing order (from left to right, eg., 877550) are written as a sequence in increasing order. Find the 2005-th number in this sequence.


The answer is 864110.

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.

2 solutions

Joe Mansley
Jun 13, 2019

We can represent any number in the sequence by the differences between digits. For example, 877550 could be represented as (1,0,2,0,5,0). The sum of these is equal to the 1st digit. Then for a given 1st digit, it's a simple matter of stars and bars to find how many numbers in the sequence starting with that digit. 6C5+7C5+...+12C5=1715, and adding 8C5 would bring us above 2005, so the 1st digit must be 8. And we repeat this for subsequent digits.

A CS Solution:

def isnonincreasing(n):
    if int(str(n)[0])>=int(str(n)[1]) and int(str(n)[1])>=int(str(n)[2]) and int(str(n)[2])>=int(str(n)[3]) and int(str(n)[3])>=int(str(n)[4]) and int(str(n)[4])>=int(str(n)[5]):
        return True
    else:
        return False
l=[]
for i in range(100000,1000000):
    if isnonincreasing(i)==True:
        l.append(i)
    else:
        pass
print (l[2004])

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...