## Task 2 - 240732

a) Let $M$ be the set of all numbers $x$ that have the following properties (1), (2), (3):

(1) $x$ is a six-digit natural number.

(2) $x$ has the digit sum 29.

(3) $x$ is divisible by 11.

Determine the largest element of the set $M$!

b) Let $M^{\prime}$ be the set of all numbers $x$ that, in addition to properties (1), (2), (3), also have the following property (4):

(4) No two digits of $x$ are the same.

Determine the largest element of the set $M^{\prime}$!
a) Among all numbers that satisfy (1) and (2), the largest is found by starting with as many nines as possible without exceeding the sum of 29 (i.e., exactly 3 nines), then appending the largest possible digit without exceeding 29 (i.e., the digit 2), after which only the option remains to append two zeros.

Thus, the largest number $x$ that satisfies (1) and (2) is 999200.

The next smaller number that satisfies (1) and (2) is obtained by replacing the digit 2 with 1, then appending the largest possible digit without exceeding 29 (i.e., the digit 1), after which only one zero remains. Thus, the second largest number that satisfies (1) and (2) is 999110.

Accordingly, the next smaller number that satisfies (1) and (2) is obtained by replacing the second digit 1 with 0, leaving 999101. The next smaller number that satisfies (1) and (2) is then 999020.

The requirement (3) is not met by 999200, 999110, and 999102, but is met by 999020.

Thus, it is proven: The largest element of the set $M$ is 999020.

b) Among all numbers that satisfy (1), (2), and (4), the largest is found by starting with 9, then appending the largest digit different from 9 (i.e., the digit 8), followed by the largest digit different from 9 and 8 (i.e., 7), and then the largest digit different from 9, 8, and 7 without exceeding 29 (i.e., the digit 5), leaving 987500. The next smaller numbers that satisfy (1), (2), and (4) are obtained by replacing the digit 5 with 4, resulting in (in descending order) 987410 and 987401.

Next, 4 is replaced by 3. To achieve the sum of 2 for the last two digits while maintaining (4), 987320 and 987302 remain.

If 3 is replaced by 2, then 987230 and 987203 remain. If 2 is replaced by 1, the largest possible result is 987140.

The requirement (3) is not met by 987500, 987410, 987401, 987320, 987302, 987230, and 987203, but is met by 987140.

Thus, it is proven: The largest element of the set $M^{\prime}$ is 987140.