#P1660. 数位平方和

数位平方和

Problem Description

Define S(n)S(n) as the sum of the kk-th powers of the digits of nn.

Define H(n)H(n) as the maximum value satisfying H(n)≤min⁡{n,H(S(n))}H(n) \le \min\{n, H(S(n))\}.

Compute ∑i=ABH(i) mod (107+7)\sum_{i=A}^{B} H(i) \bmod (10^7 + 7).

Input Format

One line with three integers k,A,Bk, A, B.

Output Format

One integer, equal to ∑i=ABH(i) mod (107+7)\sum_{i=A}^{B} H(i) \bmod (10^7 + 7).

2 1 5
14

Hint

For 20%20\% of the testdata, A,B≤50A, B \le 50. For 100%100\% of the testdata, 1≤A,B≤1061 \le A, B \le {10}^6, 1≤k≤61 \le k \le 6.

Translated by ChatGPT 5