#P14094. [ICPC 2023 Seoul R] Special Numbers

[ICPC 2023 Seoul R] Special Numbers

题目描述

Number theorist Dr. J is attracted by the beauty of numbers. When we are given a natural number a=a1a2ana=a_1a_2\dots a_n of nn digits and a natural number kk, aa is called kk-special if the product of all the digits of aa, i.e. a1a2ana_1a_2\dots a_n is divisible by kk. Note that the number 00 is always divisible by a natural number.

For example, if a=2349a=2349 and k=12k = 12, then the product of all the digits of aa, 2349=2162 \cdot 3 \cdot 4 \cdot 9 = 216 is divisible by k=12k = 12, so the number 23492349 is 1212-special. If a=2349a=2349 and k=16k = 16, then the product of all the digits of aa, 2349=2162 \cdot 3 \cdot 4 \cdot 9 = 216 is not divisible by k=16k = 16, so the number 23492349 is not 1616-special.

Given three natural numbers k,Lk,L, and RR, write a program to output zmod109+7z\bmod 10^9+7 where zz is the number of kk-special numbers among numbers in the range [L,R][L,R].

输入格式

Your program is to read from standard input. The input has one line containing three integers, k,Lk,L, and RR(1k1017,1LR10201 \le k \le 10^{17}, 1 \le L\le R\le 10^{20} ).

输出格式

Your program is to write to standard output. Print exactly one line. The line should contain zmod109+7z\bmod 10^9+7 where zz is the number of kk-special numbers among the numbers in the range [L,R][L,R], where both LL and RR are inclusive in the range.

5 1 20
4
5 50 100
19
15 11 19
0