BZOJ 3028
直接推生成函数,即
$$\begin{align}
F(z)&=\frac{1}{1-z^2}\cdot(1+z)\cdot(1+z+z^2)\cdot\frac{z}{1-z^2}\cdot\frac{1}{1-z^4}\cdot(1+z+z^2+z^3)\cdot(1+z)\cdot\frac{1}{1-z^3}\\
&=(\frac{1}{1-z})^3\cdot\frac{z}{1-z}\\
&=\frac{z}{(1-z)^4}
\end{align}$$
故
$$[z^n]F(z)=\binom{n+2}{n-1}=\binom{n+2}{3}=\frac{n(n+1)(n+2)}{6}$$
直接算就行了
const int MAXN = 500 + 5, MOD = 10007, INV_6 = 1668; IL int add(int a, int b) { a += b; return a >= MOD ? a - MOD : a; } IL int mul(int a, int b) { return a * b % MOD; } char str[MAXN]; int main() { scanf("%s", str + 1); int len = strlen(str + 1), result = 0; For(i, 1, len) { result = add(mul(result, 10), str[i] - '0'); } printf("%d\n", mul(INV_6, mul(result, mul(result + 1, result + 2)))); return 0; }