Thứ Sáu, 13 tháng 5, 2022

BINHPHUONG Pascal

var k:int64;
function check(s:int64):int64;
var u:longint;
    d,uu:int64;
    t:longint;
begin
    d:=0;
    t:=trunc(sqrt(s));
    for u:=1 to t do
    begin
        uu:=1*u;
           inc(d,trunc(sqrt(s-uu*uu)));
       // if d>=k then exit(true);
    end;
    exit(d);
end;

function tknp(l,r:int64):int64;
var m,res:int64;
begin
    while l<=r do
    begin
        m:=(l+r) div 2;
        if check(m)>=k then
        begin
            res:=m;
            r:=m-1;
        end
        else
            l:=m+1;
    end;
    exit(res);
end;

procedure giai;
var res:int64;
begin
    res:=tknp(1,trunc(1e12));
    write(res);
end;

begin
    assign(input,'binhphuong.inp');reset(input);
    assign(output,'binhphuong.out');rewrite(output);
    read(k);
    giai;
end.

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.