bzoj1053 搜索

2013-11-16 17:43

原题传送门http://www.lydsy.com/JudgeOnline/problem.php?id=1053

因为使pi(prime[i])<20亿的i不会太大,大概二十几,所以直接搜就行了

//By BLADEVIL
var
    n                                   :int64;
    prime                               :array[0..100] of longint;
    mindiv                              :array[0..10000] of longint;
    i, j                                :longint;
    ansnum, ansx                        :int64;
     
procedure dfs(d,p,sum,ans:int64);
var
    i                                   :longint;
     
begin
    if sum>n then exit;
    if (ans>ansnum) or (ans=ansnum) and (sum<ansx) then
    begin
        ansx:=sum;  
        ansnum:=ans;
    end;
    if(sum*prime[d]>n) then exit;
     
    dfs(d,p+1,sum*prime[d],ans+ans div (p+1));
    dfs(d+1,1,sum*prime[d+1],ans*2);
end;
     
begin
    read(n);
    if n=1 then
    begin
        writeln(1);
        halt;
    end;
    for i:=2 to 40 do
    begin
        if mindiv[i]=0 then
        begin
            inc(prime[0]);
            prime[prime[0]]:=i;
            mindiv[i]:=i;
        end;
        for j:=1 to prime[0] do
        begin
            if prime[j]*i>40 then break;
            mindiv[i*prime[j]]:=prime[j];
            if i mod prime[j]=0 then break;
        end;
    end;
    dfs(1,1,2,2);
    writeln(ansx);
end.

 

posted on 2013-11-20 14:33  BLADEVIL  阅读(257)  评论(0编辑  收藏  举报