Cod sursa(job #116228)

Utilizator Pepelea_FlaviuFlaviu Pepelea Pepelea_Flaviu Data 17 decembrie 2007 23:32:50
Problema Multiplu Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.12 kb
var a,b,ct,max:longint;
    fi,fo:text;
    rez,i:int64;
    baza:array[1..21]of byte;
function binar(a:int64):int64;
var numar2:int64;
    uc,ct,i:integer;
begin
  numar2:=0; ct:=0;
  while a<>0 do
    begin
      uc:=a and 1;
      inc(ct); baza[ct]:=uc;
      a:=a shr 1;
    end;
  for i:=ct downto 1 do
    numar2:=numar2*10+baza[i];
  binar:=numar2;
end;
function solv:int64;
var rez2:int64;
begin
   if (a and 1=0)or(b and 1=0) then
  begin
  i:=ct;
  while i<=1048576 do
    begin
      rez2:=binar(i);
      if (rez2 mod a=0)and(rez2 mod b=0) then begin solv:=rez2; exit; end;
      inc(i,2);
    end; end
  else
   begin
     i:=ct;
  while i<=1048576 do
    begin
      rez2:=binar(i);
      if (rez2 mod a=0)and(rez2 mod b=0) then begin solv:=rez2; exit; end;
      inc(i);
    end; end
end;
begin
  assign(fi,'multiplu.in'); reset(fi);
  assign(fo,'multiplu.out'); rewrite(fo);
  read(fi,a,b);
  if a>b then max:=a
         else max:=b;
  while max<>0 do
    begin
      inc(ct);
      max:=max div 10;
    end;
  ct:=1 shl ct;
  writeln(fo,solv);
  close(fi);
  close(fo);
end.