比赛 20101101 评测结果 AAAAAAAAAA
题目名称 整数合并 最终得分 100
用户昵称 亟隐 运行时间 0.031 s
代码语言 Pascal 内存使用 8.76 MiB
提交时间 2012-11-05 09:43:07
显示代码纯文本
var     a,f:array[0..1001000]of longint;
        b:array[0..1001000]of boolean;
        l,r,p,i,n,j,t:longint;

procedure init;
begin
        readln(l,r,p); n:=0;
        for i:=1 to r do f[i]:=i;
end;

procedure deal;
begin
        for i:=2 to r do if not b[i] then
        begin
                j:=i; inc(n); a[n]:=i;
                while  j+i<=r do
                begin
                        j:=j+i;
                        b[j]:=true;
                end;
        end;
end;

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

procedure work;
begin
        deal; j:=1; while (a[j]<p)and(j<=n) do inc(j);
        for i:=j to n do
        begin
                t:=a[i]; while t<l do t:=t+a[i];
                while t+a[i]<=r do
                begin
                        f[find(t)]:=find(t+a[i]);
                        t:=t+a[i];
                end;
        end;
        fillchar(b,sizeof(b),0); n:=0;
        for i:=l to r do b[find(i)]:=true;
        for i:=1 to r do if b[i] then inc(n);
        writeln(n);
end;

begin
assign(input,'setb.in');reset(input);
assign(output,'setb.out');rewrite(output);
        init;
        work;
close(input); close(output);
end.