显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using std::cin;
using std::cout;
using std::endl;
bool _select[5000001];
long long count = 0;
inline bool contains(int a,int b){
while(a>10){
if(a%10==b)
return true;
a/=10;
}
return (a==b);
}
int main(int argc,char ** argv){
freopen("qprime.in","r",stdin);
freopen("qprime.out","w+",stdout);
int a,b,d;
cin>>a>>b>>d;
for(int x=0;x<=b;x++)
_select[x] = true;
_select[0] = false;
for(int x=2;x<=b;x++){
if(_select[x])
for(int y=2;y*x<=b;y++)
_select[y*x] = false;
}
for(int x=a;x<=b;x++){
//cout<<x<<endl;
if(_select[x]&&contains(x,d)){
//cout<<"s"<<endl;
count++;
}
}
cout<<count<<endl;
return 0;
}