比赛 20101101 评测结果 AAAAAAAATT
题目名称 整数合并 最终得分 80
用户昵称 Vow Ryan 运行时间 2.020 s
代码语言 Pascal 内存使用 1.17 MiB
提交时间 2012-11-05 11:03:47
显示代码纯文本
var
 f:array[0..210000]of longint;
 v:array[0..210000]of boolean;
 i,j,k,l,m,n,r,p,st,ed,x,y,ans:longint;

function find(x:longint):longint;
 begin
  if f[x]=x then exit(x);
  f[x]:=find(f[x]);
  exit(f[x]);
 end;

begin
 assign(input,'setb.in');reset(input);
 assign(output,'setb.out');rewrite(output);
 read(l,r,p);
 
 for i:=2 to r do v[i]:=true;
 i:=1;
 while i<r do
  begin
   inc(i);
   for j:=2 to r div i do v[i*j]:=false;
  end;
 
 for i:=l to r do f[i]:=i;
 
 for i:=p to r do
  if v[i] then
   begin
    st:=l div i;
    ed:=r div i;
    for j:=st to ed-1 do if (j*i>=l)and(j*i<=r) then 
     for k:=st+1 to ed do  if (k*i>=l)and(k*i<=r) then 
      begin
       x:=find(j*i);y:=find(k*i);
       f[x]:=y;
      end;
   end;
 
 for i:=l to r do
  if f[i]=i then inc(ans);
 writeln(ans);
 close(output);
end.