Pagini recente » Cod sursa (job #1056031) | Cod sursa (job #1937579) | Cod sursa (job #5979) | Profil Robybrasov | Cod sursa (job #222720)
Cod sursa(job #222720)
program multiplu;
var f:text;
r,n,ind,ult,a,b,m:int64;
c,v:array [1..20000] of integer;
ok:array [1..20000] of boolean;
gata:boolean;
function cmmdc(x,y:longint):longint;
begin
repeat
if x>y then
x:=x-y
else
y:=y-x
until x=y;
cmmdc:=x
end;
function numar(o,i:longint):longint;
var j,nr:longint;
begin
if c[i]=1 then
begin
nr:=1;
for j:=1 to o do
nr:=nr*10;
end
else
nr:=0;
if v[i]>0 then
numar:=nr+numar(o+1,v[i])
else
numar:=nr
end;
begin
assign(f,'multiplu.in'); reset(f);
readln(f,a,b);
close(f);
m:=cmmdc(a,b);
m:=a*b div m;
v[1]:=0;
c[1]:=1;
r:=0;
ind:=1;
ult:=1;
gata:=false;
repeat
n:=numar(1,ind);
if n mod m=0 then
begin
gata:=true;
r:=n
end
else
if not ok[n mod m] then
begin
ult:=ult+1;
ok[n mod m]:=true;
c[ult]:=0;
v[ult]:=ind;
end;
n:=n+1;
if n mod m=0 then
begin
gata:=true;
r:=n
end
else
if not ok[n mod m] then
begin
ult:=ult+1;
ok[n mod m]:=true;
c[ult]:=1;
v[ult]:=ind;
end;
ind:=ind+1;
until gata;
assign(f,'multiplu.out'); rewrite(f);
writeln(f,r);
close(f);
end.