Interesting numbers
Practice
2.8 (5 votes)
Easy Medium
Easy Med
Problem
42% Success 2449 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Let us call a number interesting if it is divisible by P and each of its digit is equal to some digit of the interesting set. You are given the interesting set and the number P, you need to calculate the count of interesting numbers between two given values L and R (inclusive).

Input:

First line of input contains 4 space separated integers P, L, R and Z. Here P, L and R are as defined in the problem statement, and Z is the size of the interesting set. Next line contains Z space separated integers, where the \(i^{th}\) integer \(F_i\) represents the \(i^{th}\) number of the interesting set.

Output:

Print the count of interesting numbers in the range L to R inclusive.

Constraints:

\(1 \le L \le R \le 10^{18}\)

\(1 \le P \le 10^5\)

\(1 \le Z \le 10\)

\(0 \le F_i \le 9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
1 votes
Tags:
AlgorithmsDynamic ProgrammingModular arithmeticEasy-Medium
Points:30
35 votes
Tags:
Dynamic Programming簡単-普通Algorithms3 DimensionaldpEasy-Medium