Thứ Ba, 3 tháng 5, 2022

UCLN Pascal

const fi='ucln.inp';fo='ucln.out';
var n,i:longint;
    a:array[1..1000000] of longint;

function gcd(x,y:longint):longint;
var t:longint;
begin
    while y>0 do
    begin
        t:=x mod y;
        x:=y;
        y:=t;
    end;
    exit(x);
end;

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

procedure giai
var res,i:longint;
begin
    res:=a[1];
    for i:=2 to n do
          res:=gcd(res,a[i]);
    writeln(res);
end;

begin
//    assign(input,fi);reset(input);
//    assign(output,fo);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.