#P11435. Advanced Counting Game

    ID: 13514 Type: Default 1000ms 256MiB

Advanced Counting Game

Advanced Counting Game

In this problem, you are given five positive integers l, r, a, b, c. Consider each integer x in the range \([l, r]\) (inclusive). A number x is valid if and only if all of the following conditions hold:

  • The decimal representation of x does not contain the decimal representation of a as a substring.
  • Every non-empty prefix of the decimal representation of x, when interpreted as an integer, is not divisible by b. In other words, for every i (1 ≤ i ≤ |x|), the integer formed by the first i digits of x is not a multiple of \(b\).
  • Every non-empty suffix of the decimal representation of x, when interpreted as an integer, is not divisible by c. That is, for every i (1 ≤ i ≤ |x|), the integer formed by the last i digits of x is not a multiple of \(c\).

Your task is to count how many integers in the interval \([l, r]\) satisfy all these conditions.

Note: The decimal representations do not include any leading zeroes.

inputFormat

The input consists of a single line containing five positive integers:

l r a b c

where \(l\) and \(r\) are the bounds of the range and \(a, b, c\) are the parameters used in the rules.

outputFormat

Output a single integer, the count of integers \(x\) in the interval \([l, r]\) that satisfy all the given conditions.

sample

1 20 3 2 5
6