Number theory recursion congruence problem. this is a problem a friend of mine asked me: for any integer $n: a_1=n $ and for $a_k$ and $k$ an integer such that $k>1$ we have a_k the only integer such that $0\leq a_k<k$ and $\sum_{i=1}^ka_i$ is a multiple of $ k$. Prove that for any n there exists a $l$ such that if $x>l$ and $y>l$ then $a_x=a_y$.
 A: Note that $n$ might be negative, which might cause problems. 
Let $b_k=\sum_{i=1}^{k}{a_i}$. If $b_k$ is constant from some point on, there exists $l$ such that $b_k=b \, \forall k \geq l$. Then for $k>l$ we have $a_k=b_k-b_{k-1}=b-b=0$ so if $x>l, y>l$ then $a_x=0=a_y$.
Otherwise $b_k$ is not eventually constant. Also, $b_k$ is non-decreasing and $b_k$ takes on integer values, so eventually $b_k$ must be non-negative, say $b_k \geq 0 \, \forall k>j$.
Let $c_k=\frac{b_k}{k}$. Then $c_k$ are integers by definition. Consider $k>j$, so that $b_k \geq 0$ so $c_k \geq 0$. Then $(k+1)c_{k+1}=b_{k+1}=b_k+a_{k+1}<b_k+k+1=kc_k+k+1 \leq (c_k+1)(k+1)$, where the last inequality holds since $c_k \geq 0$. Thus $c_{k+1}<c_k+1$, so since $c_k, c_{k+1}$ are integers, $0 \leq c_{k+1} \leq c_k$.
Thus $c_k$ is a non-increasing sequence of non-negative integers for $k>j$, and so must eventually be constant. Thus there exists $l>j$ s.t. $c_k=c \, \forall k \geq l$. Then for $k>l$ we have $a_k=b_k-a_{k-1}=kc_k-(k-1)c_{k-1}=kc-(k-1)c=c$, so if $x>l, y>l$ then $a_x=c=a_y$.
A: Ok, if we take that for a certain $k \sum_{i=1}^k=m(k)$ then if we set $a_{k+1}=m$ then $\sum_{i=1}^{k+1}=m(k+1)$ That means that if for some $r$ we have $\frac{\sum_{i=1}^r a_i}{r}<r$ then after that all $a_i$'s will be r.
Since the sum of $a_1$ up to $a_w$ is at most $\frac{w(w+1)}{2}+n$ then the term we wish to pass as $a_{w+1}$ is at most $\frac{w+1}{2}+\frac{n}{2}$ however if w is greater than 3n we can see that $\frac{w+1}{3}>n$ and so $ \frac{w+1}{2}+n<5\frac{w+1}{6}$ which is less that w if w>6. Therefore we can find a w so that the terms after are constant.
