Program HOC24;
var a,b,i,t: integer;
function ucln(x,y: integer): integer;
var tg:integer;
begin
while y<>0 do
begin
tg:=x mod y;
x:=y;
y:=tg;
end;
ucln:=x;
end;
begin
write('Nhap a : '); readln(a);
write('Nhap b : '); readln(b);
t:=0;
for i:=1 to ucln(a,b) do
if ucln(a,b) mod i=0 then t:=t+i;
write(t);
readln
end.
uses crt;
var a,b,t,i:integer;
begin
clrscr;
write('Nhap a='); readln(a);
write('Nhap b='); readln(b);
if a<b then
begin
t:=0;
for i:=1 to a do
if (a mod i=0) and (b mod i=0) then t:=t+i;
writeln('Tong cac uoc chung cua ',a,' va ',b,' la: ',t);
end
else begin
t:=0;
for i:=1 to b do
if (a mod i=0) and (b mod i=0) then t:=t+i;
writeln('Tong cac uoc chung cua ',a,' va ',b,' la: ',t);
end;
readln;
end.