#include<iostream>#include<vector>#include<cstring>usingnamespace std;constint N =12, M =110;int l, r, p;int f[N][N][M];intmod(int x){return(x % p + p)% p;}voidinitialize(){memset(f,0,sizeof(f));for(int i =0; i <=9;++ i)++ f[1][i][i % p];for(int i =2; i < N;++ i)for(int j =0; j <=9;++ j)for(int k =0; k < p;++ k)for(int l =0; l <=9;++ l)
f[i][j][k]+= f[i -1][l][mod(k - j)];}intcount(int n){if(n ==0)return1;
vector<int> a;while(n >0){
a.push_back(n %10);
n /=10;}int res =0, last =0;for(int i = a.size()-1; i >=0;-- i){int val = a[i];for(int j =0; j < val;++ j)
res += f[i +1][j][mod(-last)];
last += val;if(i ==0&& last % p ==0)++ res;}return res;}intmain(){while(cin >> l >> r >> p){initialize();
cout <<count(r)-count(l -1)<< endl;}return0;}