牛客-金币

https://www.nowcoder.com/acm/contest/170/A

var
    l,r,tot,pre,i:qword;
function max(a,b:int64):int64;
begin
    if a>b then exit(a) else exit(b);
end;
function o(a:int64):int64;
begin
    if a<0 then exit(0) else exit(a);
end;
begin
    readln(l,r);
    tot:=0;i:=1;pre:=0;
    while i*i+pre<=r do
    begin
      tot:=tot+o(pre+i*i-max(l-1,pre))*i;
      pre:=pre+i*i;
      inc(i);
    end;
    tot:=tot+(r-pre)*i;
    writeln(tot);
end.
全部评论

相关推荐

投递腾讯云智研发等公司10个岗位
点赞 评论 收藏
转发
2 1 评论
分享
牛客网
牛客企业服务