Cod sursa(job #115354)

Utilizator tiger_10Dutescu Radu Alin tiger_10 Data 16 decembrie 2007 12:19:14
Problema Multiplu Scor 0
Compilator fpc Status done
Runda preONI 2008, Runda 2, Clasele 11-12 Marime 0.76 kb
var a,b,c,d,i,x,y,k:longint;
   ok:boolean;
   f,g:text;
begin
 assign(f,'multiplu.in');
 reset(f);
 read(f,a);
 readln(f,b);
 close(f);
 if b>a then begin
  a:=a+b;
  b:=a-b;
  a:=a-b;
  end;
 x:=a;
 repeat
  x:=x div 10;
  inc(k);
  until x=0;
 x:=1;
 y:=1;
 for i:=1 to k do begin
  x:=x*10;
  y:=y*10 +1;
  end;
 c:=a;
 repeat
  ok:=false;
  if (c>x)and(c<y) then
   if c mod b =0 then begin
    d:=c;
    ok:=true;
    repeat
     if (d mod 10)>1 then ok:=false;
      d:=d div 10;
    until d=0;
   end;
    if ok=false then begin
     x:=x*10;
     y:=y*10+1;
     repeat
      c:=c+a;
      until c>=x;
    end;
 until (ok=true)or(c>100000000);
 assign(g,'multiplu.out');
 rewrite(g);
 write(g,c);
 close(g);
end.