标签:des style blog http color os io 数据
1 var i,n,ans:longint; 2 begin 3 assign(input,‘input.txt‘);assign(output,‘output.txt‘); 4 reset(input);rewrite(output); 5 readln(n); 6 for i:=1 to n do inc(ans,n div i); 7 writeln(ans); 8 close(input);close(output); 9 end.
2.正解
1 const maxn=1000000+1000; 2 var ans:int64; 3 f,p:array[0..maxn] of int64; 4 check:array[0..maxn] of boolean; 5 i,n,tot:longint; 6 procedure getprimes; 7 var i,j,k:longint; 8 begin 9 fillchar(check,sizeof(check),false); 10 for i:=2 to n do 11 begin 12 if not(check[i]) then begin inc(tot);p[tot]:=i;end; 13 for j:=1 to tot do 14 begin 15 k:=i*p[j]; 16 if k>n then break; 17 check[k]:=true; 18 if i mod p[j]=0 then break; 19 end; 20 end; 21 end; 22 procedure dfs(x,pos:int64); 23 var y:int64;i:longint; 24 begin 25 if pos>tot then exit; 26 y:=x;dfs(x,pos+1); 27 for i:=1 to 22 do 28 begin 29 y:=y*p[pos];if y>n then break; 30 f[y]:=f[x]*(i+1); 31 dfs(y,pos+1); 32 end; 33 end; 34 35 procedure main; 36 begin 37 getprimes; 38 f[1]:=1; 39 dfs(1,1); 40 ans:=1; 41 for i:=2 to n do inc(ans,f[i]); 42 writeln(ans); 43 end; 44 45 begin 46 assign(input,‘input.txt‘);assign(output,‘output2.txt‘); 47 reset(input);rewrite(output); 48 readln(n); 49 main; 50 close(input);close(output); 51 end.
BZOJ1968: [Ahoi2005]COMMON 约数研究,布布扣,bubuko.com
BZOJ1968: [Ahoi2005]COMMON 约数研究
标签:des style blog http color os io 数据
原文地址:http://www.cnblogs.com/zyfzyf/p/3902481.html