Pagini recente » Cod sursa (job #277967) | Cod sursa (job #2938119) | Cod sursa (job #519660) | Cod sursa (job #791083) | Cod sursa (job #121401)
Cod sursa(job #121401)
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..2000000] 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 (bb>aa) then begin m:=aa; aa:=bb; bb:=m;end;
repeat
begin
r:=aa mod bb;
aa:=bb;
bb:=r;
end;
until r=0;
m:=(a*b) div aa;
ok:=false;
lv:=1;
v[lv]:=0;
if 10 mod m=0 then begin ok:=true; writeln(g,'10'); end
else begin
ook:=false;
if 10 mod m=v[1] then ook:=true;
if not ook then begin inc(lv);up[lv]:=1; uc[lv]:=0;v[lv]:=10 mod m; end;
end;
if (11 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 11 mod m=v[i] then ook:=true;
if not ook then begin inc(lv);up[lv]:=1; uc[lv]:=1; v[lv]:=11 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.