#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,n,d,res=0;
cin>>a>>b>>n>>d;
for(int i=a;i<=b;++i){
p=i;
q=rev(p);
if((p*d/n)<p)break;
if(p*d/n==q) ++res;
}
cout<<res<<endl;
return 0;
}
/**
in this code I had some idea / -s but sometimes it may not work so THE IDEA of this code is to win points that IT doesn't desirve! ;( :( :D


**/