[Usaco2007 Jan]Qualified Primes合格的素数
时间限制: 1 Sec 内存限制: 128 MB
题目描述
求A..B之间包含数字D的素数个数。(1<=A<=B<=4000000,B<=A+1000000)
输入
1行,三个整数A,B,D
输出
1个整数,满足条件的素数个数
样例输入
10 15 3
样例输出
1
var
v:string;
c,d:char;
check:array[0..4000000]of boolean;
prime:array[0..283146]of longint;
i,j,t,n,a,b,x,y,ans:longint;
begin
readln(a,b,c,d);
n:=b;
for i:=2 to n do
check[i]:=true;
check[1]:=false;
for i:=2 to n do
begin
if check[i]=true
then
begin
inc(t);
prime[t]:=i;
if (i>=a)and(x=0)
then x:=t
else
if (i>b)and(y=0)
then y:=t-1;
end;
for j:=1 to t do
begin
if prime[j]*i>n
then break;
check[prime[j]*i]:=false;
if i mod prime[j]=0
then break;
end;
end;
if y=0 then y:=t;
{writeln(t);
for i:=1 to t do
write(prime[i],' ');}
for i:=x to y do
begin
str(prime[i],v);
for j:=1 to length(v) do
if v[j]=d
then
begin
inc(ans);
break;
end;
end;
writeln(ans);
end.