Cod sursa(job #602387)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 11 iulie 2011 12:10:41
Problema Algoritmul lui Euclid Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.84 kb
Program divizor;
 var a, b,i,j,t:longint;
     fi, fo:text;
begin
 assign(fi,'euclid2.in');
  reset(fi);
   readln(fi,t);
 assign(fo,'euclid2.out');
  rewrite(fo);
for j:=1 to t do begin
     readln(fi,a,b);
 if a>=b then
    if a mod b=0 then
                  writeln(fo,b)
 else
   for i:=b downto 1 do
     if (a mod i=0) and (b mod i=0) then begin
                                          writeln(fo,i);
                                          break;
                                         end;
 if b>=a then
  if b mod a=0 then
                 writeln(fo,a)
  else
   for i:=a downto 1 do
    if (a mod i=0) and (b mod i=0) then begin
                                          writeln(fo,i);
                                          break;
                                         end;
   end;
 close(fo);
end.