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

AOAM Pascal

var a:array[1..1005] of longint;
        n,s,i:Longint;

function check(x:longint):boolean;
var i,t:longint;
begin
        t:=0;
        for i:=1 to n do
        begin
                t:=t+a[i];
                if t=x then t:=0
                else
                        if t>x then exit(false);
        end;
        exit(true);

end;

procedure nhap;
var i:longint;
begin
        readln(n);
        for i:=1 to n do read(a[i]);
end;

procedure giai;
begin
        s:=0;
        for i:=1 to n do s:=s+a[i];
        for i:=1 to s do
                if s mod i = 0 then
                        if check(i)=true then
                        begin
                                write(s div i);
                                exit;
                        end;
        write(0);
end;

begin
        assign(input,'chiaao.inp');reset(input);
        assign(output,'chiaao.out');rewrite(output);
        nhap;
        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.