Special Numbers

시간 제한1.5초메모리 제한2048 MB

요약
k, L, R이 주어질 때 [L, R] 구간에서 각 자릿수의 곱이 k로 나누어떨어지는 수의 개수를 10^9+7로 나눈 나머지를 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 정수론, 수학, 구현
정답자
아직 제출이 없습니다

문제

Number theorist Dr. J is attracted by the beauty of numbers. When we are given a natural number a=a_1a_2⋯a_na = a\_1a\_2 \cdots 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. a_1⋅a_2⋅a_3⋯a_na\_1 \cdot a\_2 \cdot a\_3 \cdots 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, 2⋅3⋅4⋅9=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, 2⋅3⋅4⋅9=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 kk, LL, and RR, write a program to output z mod (109+7)z \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, kk, LL, and RR (1≤k≤10171 ≤ k ≤ 10^{17}, 1≤L≤R≤10201 ≤ L ≤ R ≤ 10^{20}).

출력

Your program is to write to standard output. Print exactly one line. The line should contain z mod (109+7)z \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.

예제3

  1. 예제 1

    입력
    5 1 20
    
    예상 출력
    4
    
  2. 예제 2

    입력
    5 50 100
    
    예상 출력
    19
    
  3. 예제 3

    입력
    15 11 19
    
    예상 출력
    0