For each positive integer $k$ let $a_k$ be the largest divisor of $k$ which is not divisible by $3$. Let $s_n=a_1+a_2+\dots+a_n$. Show that: (a) The number $s_n$ is divisible by $3$ iff the number of ones in the ternary expansion of $n$ is divisible by $3$. (b) There are infinitely many $n$ for which $s_n$ is divisible by $3^3$.
Problem
Source: Bundeswettbewerb Mathematik 2022, Round 1 - Problem 4
Tags: number theory, number theory proposed, divisor, sum of divisors