#include<iostream>
#include<cmath>
using namespace std;
unsigned long long rev(unsigned long long a){
    unsigned long long res=0;
    while(a!=0){
          res*=10;
          res+=a%10;
          a/=10;   
    }
    return res;
}
int main(){
unsigned long long a,b,p,q;
int n,d,res=0;
cin>>a>>b>>n>>d;
for(p=a;p<=b;++p){
q=rev(p);
if(p*d/n==q) ++res;
}
cout<<res<<endl;
return 0;
}