Cod sursa(job #262088)

Utilizator MihaiBunBunget Mihai MihaiBun Data 18 februarie 2009 23:13:35
Problema Multiplu Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.03 kb
program vvv;
var f:text;
    z:array[1..10000] of 0..1;
    x,y,a,b,m,i,r,n,s:longint;
    gasit:boolean;
begin
  assign(f,'multiplu.in');
  reset(f);
  readln(f,a,b);
  close(f);
  assign(f,'multiplu.out');
  rewrite(f);
  x:=a;
  y:=b;
  r:=x mod y;
  while r<>0 do
    begin
     x:=b;
     y:=r;
     r:=x mod y
    end;
   m:=(a div y)*b;
   gasit:=false;
   n:=1;
   z[1]:=0;
   while not gasit do
     begin
       if z[1]=0 then z[1]:=1
                 else begin
                        i:=1;
                        while z[i]=1 do begin
                                          z[i]:=0;
                                          i:=i+1
                                        end;
                        z[i]:=1;
                        if i>n then n:=i;
                      end;
       s:=0;
       for i:=n downto 1 do
         begin
           s:=s*10+z[i];
           s:=s mod m
         end;
       if s=0 then gasit:=true
     end;
   for i:=n downto 1 do write(f,z[i]);
   close(f);
end.