#include <bits/stdc++.h>
using namespace std;
static const long long INF = 1LL << 61LL;
static const long long mod = 10000;
string str1, str2;
int M;
long long ans;
char c[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
long long cal1(int n, int p, int pp, int mod, string s) {
  long long res = 0;
  if (n == str2.size() - 2)
    return 0;
  else if (n == 0) {
    for (int i = 0; i < 10; ++i) {
      int temp = mod * 10;
      temp += i;
      if (i > p || i < p) {
        if (!(temp % M) && n + 1 > str1.size()) {
          res += cal1(n + 1, i, p, 0, s + c[i]) + 1;
        } else
          res += cal1(n + 1, i, p, temp % M, s + c[i]);
      }
    }
  } else {
    for (int i = 0; i < 10; ++i) {
      int temp = mod * 10;
      temp += i;
      if (p < pp && p < i) {
        if (!(temp % M) && n + 1 > str1.size() - 1) {
          res += cal1(n + 1, i, p, 0, s + c[i]) + 1;
        } else
          res += cal1(n + 1, i, p, temp % M, s + c[i]);
      } else if (p > pp && p > i) {
        if (!(temp % M) && n + 1 > str1.size() - 1) {
          res += cal1(n + 1, i, p, 0, s + c[i]) + 1;
        } else
          res += cal1(n + 1, i, p, temp % M, s + c[i]);
      }
    }
  }
  return res;
}
long long cal2(int n, int p, int pp, int mod, int f, string s) {
  long long res = 0;
  if (n == str1.size() - 1 && mod == 0 && f) {
    return 1;
  } else if (n == str1.size() - 1)
    return 0;
  for (int i = 0; i < 10; ++i) {
    int b = f;
    if (b == 2) {
      if (str1[n + 1] - '0' < i) {
        b = 1;
      } else if (str1[n + 1] - '0' == i) {
        b = 2;
      } else if (str1[n + 1] - '0' > i) {
        b = 0;
      }
    }
    int temp = mod * 10;
    temp += i;
    if ((p < pp && p < i) || (n == 0 && p < i)) {
      res += cal2(n + 1, i, p, temp % M, b, s + c[i]);
    } else if ((p > pp && p > i) || (n == 0 && p > i)) {
      res += cal2(n + 1, i, p, temp % M, b, s + c[i]);
    }
  }
  return res;
}
long long cal3(int n, int p, int pp, int mod, int f, string s) {
  long long res = 0;
  if (n == str2.size() - 1 && mod == 0 && f) {
    return 1;
  } else if (n == str2.size() - 1)
    return 0;
  for (int i = 0; i < 10; ++i) {
    int b = f;
    if (b == 2) {
      if (str2[n + 1] - '0' > i) {
        b = 1;
      } else if (str2[n + 1] - '0' == i) {
        b = 2;
      } else if (str2[n + 1] - '0' < i) {
        b = 0;
      }
    }
    int temp = mod * 10;
    temp += i;
    if ((p < pp && p < i) || (n == 0 && p < i)) {
      res += cal3(n + 1, i, p, temp % M, b, s + c[i]);
    } else if ((p > pp && p > i) || (n == 0 && p > i)) {
      res += cal3(n + 1, i, p, temp % M, b, s + c[i]);
    }
  }
  return res;
}
int main() {
  cin >> str1 >> str2;
  cin >> M;
  for (int i = 1; i <= 9; ++i) {
    string str;
    str += c[i];
    if (str2[0] - '0' >= i && i != 0) {
      if (str2[0] - '0' > i)
        ans += cal3(0, i, 0, i % M, 1, str);
      else
        ans += cal3(0, i, 0, i % M, 2, str);
    }
    if (str1.size() == str2.size()) continue;
    if ((str1.size() - 1 == 0 && i >= str1[0] - '0') || str1.size() - 1 > 0) {
      if (str1[0] - '0' < i)
        ans += cal2(0, i, 0, i % M, 1, str);
      else if (str1[0] - '0' == i)
        ans += cal2(0, i, 0, i % M, 2, str);
    }
    ans += cal1(0, i, 0, i % M, str);
  }
  cout << ans << endl;
}
