朴素能得个差不多吧……

这题改进算法真恶心

pascal一直过不了,难道非得转c++?

代码:(pascal)

 1 var n,k,i,l,r,m:longint;
 2     ans:qword;
 3 function ceil(x:real):longint;
 4  begin
 5  if trunc(x)<x then exit(trunc(x)+1) else exit(trunc(x));
 6  end;
 7 procedure main;
 8  begin
 9    readln(n,k);
10    ans:=0;
11    if n>k then
12     begin
13      inc(ans,(n-k)*k);
14      n:=k;
15     end;
16    m:=ceil(sqrt(k));
17    for i:=1 to m do inc(ans,k mod i);
18    for i:=1 to m do
19     begin
20       l:=(k div (i+1))+1;
21       r:=(k div i);
22       if l<=m then l:=m+1;
23       if r>n then r:=n;
24       if r<l then continue;
25       inc(ans,(((k<<1)-i*(l+r))*(r-l+1)>>1));
26     end;
27    writeln(ans);
28  end;
29 begin
30   main;
31 end.    
View Code

相关文章:

  • 2021-05-19
  • 2021-12-15
  • 2021-07-08
  • 2021-08-30
  • 2022-01-16
  • 2021-10-16
猜你喜欢
  • 2022-12-23
  • 2021-11-29
  • 2022-02-10
  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案