C1. The function $f$ is defined on the natural numbers $1,2,3, \ldots$ by $f(1)=1$ and
$$
f(n)=\left\{\begin{array}{ll}
f\left(\frac{n}{10}\right) & \text { if } 10 \mid n \\
f(n-1)+1 & \text { otherwise }
\end{array}\right.
$$

Note: The notation $b \mid a$ means integer number $a$ is divisible by integer number $b$.
(a) Calculate $f(2019)$.
(b) Determine the maximum value of $f(n)$ for $n \leq 2019$.
(c) A new function $g$ is defined by $g(1)=1$ and
$$
g(n)=\left\{\begin{array}{ll}
g\left(\frac{n}{3}\right) & \text { if } 3 \mid n \\
g(n-1)+1 & \text { otherwise }
\end{array}\right.
$$

Determine the maximum value of $g(n)$ for $n \leq 100$.
Solution for (a):
$$
\begin{aligned}
f(2019) & =f(2018)+1=f(2017)+2=\ldots=f(2010)+9=f(201)+9 \\
& =f(200)+1+9 \\
& =f(20)+1+9 \\
& =f(2)+1+9 \\
& =f(1)+1+1+9 \\
& =1+1+1+9=12 .
\end{aligned}
$$

In general, we can see that if $n \equiv m(\bmod 10)$ then $f(n)=f(n-m)+m$, where $10 \mid(n-m)$. Therefore $f(n)$ gives the sum of the digits of $n$. Indeed, $f(2019)=2+0+1+9=12$.
Answer: 12 .
Solution for (b):
We need a number where $n \leq 2019, n=1000 a+100 b+10 c+d$ and $a+b+c+d$ is maximal. If $a=2$ the maximum we can hope for is $f(2019)=12$, but if $a=1$ we have $f(1999)=28$ which is the maximum.
Answer: 28 .
Solution for (c):
Function $g$ gives the sum of the digits when $n$ is in base 3 . Since $100=81+18+1=10201_{3}, g(100)=4$ and $g$ is maximized with $2222_{3}=80$ with $g(80)=8$.
Answer: 8 .