DigIT

3.8

60 votes
Dynamic Programming, Combinatorics, Hard, Number Theory, Brute-force search, Open, Approved
Problem

This problem is as simple as short. Just find how many numbers from A to B with sum of digits from X to Y are divisible by K.

Input
The first line contains 5 space-separated positive integers: A, B, X, Y, K

Output
Output one number - answer for the question.

Constraints

  • 0 < A, B, K ≤ 1013
  • 0 < X, Y ≤ 1000
  • A ≤ B
  • 0 < A, B, ≤ 107 in 32 % of the test data
Time Limit: 5
Memory Limit: 512
Source Limit:
Explanation

There are 6 such numbers: 12, 20, 24, 32, 40, 60

Editor Image

?