比赛 |
20101101 |
评测结果 |
AAAAAAAATT |
题目名称 |
整数合并 |
最终得分 |
80 |
用户昵称 |
Abel·S |
运行时间 |
2.008 s |
代码语言 |
Pascal |
内存使用 |
1.82 MiB |
提交时间 |
2012-11-05 09:42:48 |
显示代码纯文本
program cojs_p487;
var
jud:array[0..100000] of boolean;
e:array[0..10000] of longint;
q,head,next,v:array[0..100000] of longint;
p,a,b,i,j,k,tot,sum,x,num,s0,he,ta,y:longint;
flag:boolean;
procedure eratos;
var
i,j:longint;
begin
jud[1]:=false;
for i:=2 to b do
jud[i]:=true;
for i:=2 to b div 2 do
if jud[i]
then begin
for j:=2 to b div i do
jud[i*j]:=false;
if i>=p
then begin
inc(num);
e[num]:=i;
end;
end;
end;
procedure ass;
begin
assign(input,'setb.in');
assign(output,'setb.out');
reset(input);
rewrite(output);
end;
procedure cls;
begin
close(input);
close(output);
end;
procedure add(x,y:longint);
begin
inc(tot);
v[tot]:=y;
next[tot]:=head[x];
head[x]:=tot;
end;
procedure init;
begin
ass;
readln(a,b,p);
eratos;
sum:=b-a+1;
fillchar(jud,sizeof(jud),true);
for i:=a to b do
for j:=1 to num do
if (i mod e[j]=0) and jud[e[j]]
then begin
jud[e[j]]:=false;
if a mod e[j]=0
then x:=a div e[j]
else x:=(a div e[j])+1;
for k:=x to b div e[j] do
begin
add(i,k*e[j]);
add(k*e[j],i);
end;
end;
end;
begin
init;
fillchar(jud,sizeof(jud),false);
s0:=sum;
while s0>0 do
begin
he:=0;ta:=1;
for i:=a to b do
if not(jud[i]) then begin q[ta]:=i; jud[i]:=true; dec(s0); break; end;
while he<ta do
begin
inc(he);
x:=q[he];
k:=head[x];
y:=v[k];
while k<>0 do
begin
if not(jud[y]) then begin inc(ta); q[ta]:=y; jud[y]:=true; dec(s0); dec(sum); end;
k:=next[k];
y:=v[k];
end;
end;
end;
writeln(sum);
cls;
end.