显示代码纯文本
#include<cstdio>
#include<iostream>
using namespace std;
int zsb[1001];
int a,b,d,tot,ans;
bool f(int x)
{
for (int i=2; i*i<=x; ++i)
if (x%i==0) return false;
return true;
}
bool p_one(int c)
{
for (int i=1; i<=tot; ++i)
if (c%zsb[i]==0 && zsb[i]!=c) return false;
return true;
}
bool p_two(int p)
{
int n=p;
while (n>0)
{
if (n%10==d) return true;
n/=10;
}
return false;
}
int main()
{
freopen("qprime.in","r",stdin);
freopen("qprime.out","w",stdout);
scanf("%d%d%d",&a,&b,&d);
for (int i=2; i<2000; ++i)
if (f(i)) zsb[++tot]=i;
for (int i=a; i<=b; ++i)
if (p_one(i) && p_two(i))
{
ans++;
}
printf("%d\n",ans);
}