Solution (source code)

= Solution

Since refilling is immediate, the observed arrival-state space becomes $\{1,\ldots,N\}$. A zero remainder is replaced by $N$, while all positive remainders are unchanged. Thus
$$
\boxed{P_{kN}=\frac1k,\qquad P_{kj}=\frac1k\ (1\leq j<k),\qquad P_{kj}=0\text{ otherwise}.}
$$
In particular state one moves to $N$ with <probability> one, and state $N$ has a self-loop of <probability> $1/N$.