Playing with digits

4.1

36 votes
Digit DP, Dynamic Programming, Algorithms, Advanced, Math
Problem

Determine the number of integers that are available from A to B (inclusive) and satisfy the following conditions:

  • Sum of its digits is equal to a prime number
  • Divisible by k

Input format

The first and only line contains three space-separated positive integers A, B, and K.

Output format

Print a single integer that denotes the answer to this question.

Constraints

0<A, B, K2(1010)AB

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

There are 7 such numbers: 12 16 20 32 52 56 76

Editor Image

?