PersonalCorpus 版 (精华区)

寄信人: sino (蚱蜢舟)
标  题: 1118
发信站: 哈工大紫丁香 (2002年03月23日15:27:03 星期六)
来  源: mtlab4.hit.edu.cn 

171243 07:29:24 23 Mar 2002
Bozhang,HIT,P.R.China 1118 Pascal Accepted 1.512 sec 364K

var
    p:array[1..78498] of integer;
    i,j,k,e,best:integer;
    a,b:extended;
    f:boolean;
begin
    p[1]:=2; k:=1;
    for i:=3 to 1000000 do begin
        f:=true; if k<168 then e:=k else e:=168;
        for j:=1 to e do if i mod p[j]=0 then begin
            f:=false; break;
        end;
        if f then begin
            inc(k);
            p[k]:=i;
        end;
    end;
    readln(i,j);
    if i=1 then begin
        writeln(1);
        halt
    end;
    for k:=78498 downto 1 do begin
        if p[k]<i then break;
        if p[k]<=j then begin
            writeln(p[k]);
            halt;
        end;
    end;
    for k:=168 downto 1 do begin
        e:=p[k]*p[k];
        if (e>=i) and (e<=j) then begin
            writeln(e);
            halt;
        end;
    end;
    a:=10000000; best:=i;
    for k:=i to j do begin
        b:=1;
        for e:=2 to trunc(sqrt(k)) do if k mod e=0 then begin
            b:=b+e+k div e;
        end;
        if sqr(trunc(sqrt(k)))=k then b:=b-trunc(sqrt(k));
        b:=b/k;
        if b<a then begin
            a:=b; best:=k;
        end;
    end;
    writeln(best);
end.
--
FreeBSD has a large number of afficionados who are prepared  to flame 
anybody who  dares  suggest that it's not better than Linux.

Linux has a large number of afficionados who  are  prepared  to flame 
anybody who dares suggest that it's not better than FreeBSD.

※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: mtlab4.hit.edu.cn]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.253毫秒