Cod sursa(job #121393)

Utilizator cheery_g1rlHaller Emanuela cheery_g1rl Data 8 ianuarie 2008 17:07:08
Problema Multiplu Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.22 kb
program multiplu;
var f,g:text;
    nr,lv,a,i,j,aa,bb,b,r,m,q,w:longint;
    ok,ook:boolean;
    v,uc,up:array[1..1000] of longint;
begin
 assign(f,'multiplu.in');
 reset(f);
 readln(f,a,b);
 close(f);
 assign(g,'multiplu.out');
 rewrite(g);
 aa:=a; bb:=b;
 if (b>a) then begin m:=a; a:=b; b:=m;end;
 repeat
   begin
     r:=a mod b;
     a:=b;
     b:=r;
   end;
 until r=0;
 m:=(aa*bb) div a;
 ok:=false; a:=aa; b:=bb;
 nr:=1;lv:=1;
 v[lv]:=0;
       w:=nr*10+0;
       if w mod m=0 then begin ok:=true; writeln(g,'10'); end
         else begin

      ook:=false;
      if w mod m=v[1] then ook:=true;
      if not ook then begin inc(lv);up[lv]:=1; uc[lv]:=0;v[lv]:=w mod m; end;
          end;

      w:=nr*10+1;
      if (w mod m=0)and(not ok) then begin ok:=true; writeln(g,'11');end
         else if not ok then
           begin
      ook:=false;
      for i:=1 to lv do if w mod m=v[i] then ook:=true;
      if not ook then begin inc(lv);up[lv]:=1; uc[lv]:=1; v[lv]:=w mod m; end;
           end;
    q:=2; uc[1]:=1;up[1]:=0;
  while not ok do
     begin
       r:=lv;
       for j:=q to lv do
          begin
            w:=1;
            i:=j;
            nr:=0;
            while i>=1 do
               begin
                 nr:=nr+uc[i]*w;
                 i:=up[i];
                 w:=w*10;
               end;
             w:=nr*10+0;
             if (w mod m=0)and(not ok) then begin ok:=true; writeln(g,w); end
                  else if not ok  then begin
                        ook:=false;
                        for i:=1 to lv do if  w mod m=v[i] then ook:=true;
                        if not ook then begin inc(lv);up[lv]:=j; uc[lv]:=0;v[lv]:=w mod m; end;
                       end;
             w:=nr*10+1;
             if (w mod m=0)and(not ok) then begin ok:=true; writeln(g,w);end
                    else if not ok then
                           begin
                             ook:=false;
                             for i:=1 to lv do if w mod m=v[i] then ook:=true;
                             if not ook then begin inc(lv);up[lv]:=j; uc[lv]:=1; v[lv]:=w mod m; end;
                            end;

          end;
         q:=r+1;
     end;
   close(g);
end.