Daily

Random

Practice set

Baltic Way 2025 · Problem 10

Combinatorics

A positive integer with 9 digits is called nice if it contains each digit from 1 to 9. A number is called wonderful if it is nice and for each k=1,…,9k=1,\ldots,9, it holds that the kk-th digit in the number is equal to the position of kk in the number. For example, 847296315 is wonderful:

  • the first digit is 8, which is the position of 1 in the number,
  • the second digit is 4, which is the position of 2 in the number,
  • the third digit is 7, which is the position of 3 in the number, and so on.

Show that the number of wonderful numbers is even.

Change pool

When you’re ready

Review material becomes available with the next Daily.

Review

Topics

Pigeonhole and extremal arguments

Solutions

Solution

To any nice number a1a2⋯a9a_1a_2\cdots a_9 associate another nice number b1b2⋯b9b_1b_2\cdots b_9, called its sorting number, uniquely defined by

ab1ab2⋯ab9=123456789.a_{b_1}a_{b_2}\cdots a_{b_9}=123456789.

This is well-defined because every nice number has exactly the digits 1,2,…,91,2,\ldots,9. A nice number is wonderful exactly when it is its own sorting number.

Let a1⋯a9a_1\cdots a_9 have sorting number b1⋯b9b_1\cdots b_9. For every i,j∈{1,…,9}i,j\in\{1,\ldots,9\},

bi=j  ⟺  aj=i.b_i=j\iff a_j=i.

By symmetry, a1⋯a9a_1\cdots a_9 is therefore the sorting number of b1⋯b9b_1\cdots b_9.

Thus all nice numbers that are not wonderful can be paired with their distinct sorting numbers. Hence the number of non-wonderful nice numbers is even. The total number of nice numbers is 9!9!, also even, so the number of wonderful numbers is even.

Solution 2

Generalize to nn-wonderful numbers of length nn, for 1≤n≤91\le n\le9, and let TnT_n denote their number. We have T1=1T_1=1 and T2=2T_2=2, corresponding to 11, 1212, and 2121 in the two respective lengths.

Consider an nn-wonderful number A=a1⋯anA=a_1\cdots a_n with 2<n≤92<n\le9.

  1. If an=na_n=n, then a1⋯an−1a_1\cdots a_{n-1} is an (n−1)(n-1)-wonderful number.
  2. If an=k<na_n=k<n, then ak=na_k=n. Remove kk and nn from AA and subtract 11 from every remaining digit greater than kk. This gives an (n−2)(n-2)-wonderful number.

Case 1 gives a bijection with (n−1)(n-1)-wonderful numbers. In Case 2, the reverse construction is: take an (n−2)(n-2)-wonderful number, add 11 to every digit at least kk, insert nn in position kk, and append kk. This is possible for each k∈{1,…,n−1}k\in\{1,\ldots,n-1\}.

Therefore

Tn=Tn−1+(n−1)Tn−2.T_n=T_{n-1}+(n-1)T_{n-2}.

Since T3=2+2=4T_3=2+2=4, the recurrence shows that TnT_n is even for every 2≤n≤92\le n\le9, in particular for n=9n=9.

Contest context

Results from Baltic Way 2025

11 teams

Mean score
4.8 / 5
Scores of 4 or 5
10 / 11
Estonia
5 / 5

Score distribution

00
10
20
31
40
510
All team scores
TeamScore
Germany5 / 5
Estonia5 / 5
Poland5 / 5
Lithuania5 / 5
Norway5 / 5
Latvia5 / 5
Finland3 / 5
Denmark5 / 5
Sweden5 / 5
Ukraine5 / 5
Iceland5 / 5