#include<iostream>
#include<string>
#include<cmath>
using namespace std;
long long a,b,c,d,e,f,g,h,k,sum;
string S,T,U;
int main(){
cin>>a>>b>>c>>d>>sum;
S=to_string(a);
g=S.size();
e=a/pow(10,g/2);
f=b/pow(10,g/2);
for(int i=e;i<=f;i++){
T=to_string(i);
for(int j=T.size()-1;j>=0;j--){
T+=T[j];
}
h=stoi(T);
if(h%c==0){
k=0;
for(int j=0;j<T.size();j++){
U="";U+=T[j];
k+=stoi(U);
}
if(k==d){sum++;}
}
}
cout<<sum<<endl;
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPHN0cmluZz4KI2luY2x1ZGU8Y21hdGg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpsb25nIGxvbmcgYSxiLGMsZCxlLGYsZyxoLGssc3VtOwpzdHJpbmcgUyxULFU7CgppbnQgbWFpbigpewoJY2luPj5hPj5iPj5jPj5kPj5zdW07CglTPXRvX3N0cmluZyhhKTsKCWc9Uy5zaXplKCk7CgllPWEvcG93KDEwLGcvMik7CglmPWIvcG93KDEwLGcvMik7Cglmb3IoaW50IGk9ZTtpPD1mO2krKyl7CgkJVD10b19zdHJpbmcoaSk7CgkJZm9yKGludCBqPVQuc2l6ZSgpLTE7aj49MDtqLS0pewoJCQlUKz1UW2pdOwoJCX0KCQloPXN0b2koVCk7CgkJaWYoaCVjPT0wKXsKCQkJaz0wOwoJCQlmb3IoaW50IGo9MDtqPFQuc2l6ZSgpO2orKyl7CgkJCQlVPSIiO1UrPVRbal07CgkJCQlrKz1zdG9pKFUpOwoJCQl9CgkJCWlmKGs9PWQpe3N1bSsrO30KCQl9Cgl9Cgljb3V0PDxzdW08PGVuZGw7CglyZXR1cm4gMDsKfQ==