Problem 839
Beans in Bowls
The sequence $S_n$ is defined by $S_0 = 290797$ and $S_n = S_{n - 1}^2 \bmod 50515093$ for $n>0$.
There are $N$ bowls indexed $0,1,\dots ,N-1$. Initially there are $S_n$ beans in bowl $n$.
At each step, the smallest index $n$ is found such that bowl $n$ has strictly more beans than bowl $n+1$. Then one bean is moved from bowl $n$ to bowl $n+1$.
Let $B(N)$ be the number of steps needed to sort the bowls into non-descending order.
For example, $B(5) = 0$, $B(6) = 14263289$ and $B(100)=3284417556$.
Find $B(10^7)$.
碗中豆
序列$S_n$按如下方式定义:$S_0 = 290797$;对于$n>0$,$S_n = S_{n - 1}^2 \bmod 50515093$。
有$N$个碗,其编号分别为$0,1,\dots,N-1$。一开始,编号为$n$的碗中放有$S_n$颗豆子。
接下来的每一步中,先选择编号最小的、豆子数目比后一个碗严格更多的碗$n$,再从碗$n$中移动一颗豆子到碗$n+1$。
记$B(N)$为将碗中豆子数目调整为非递降序列所需的步数。
例如,$B(5) = 0$,$B(6) = 14263289$,$B(100)=3284417556$。
求$B(10^7)$。