Cod sursa(job #223088)

Utilizator mari_anaMariana Gheorghe mari_ana Data 26 noiembrie 2008 21:37:23
Problema Multiplu Scor 30
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.85 kb
program multiplu;
type adresa=^nod;
		 nod=record
     		 cif:boolean;
         dupa,inainte:adresa;
         rest:longint;
         end;
var cap,gasit,p,c,d:adresa;
    x,a,b:longint;
    m:string;
    ok:boolean;
    v:array [0..200000] of integer;
    f:text;

function conditie(nr:longint):boolean;
var ind,ind2:longint;
begin
ind:=nr mod 200000;
ind2:=nr div 200000;
nr:=v[ind];
nr:=nr shr ind2;
if nr and 1=1 then
	conditie:=false
else
	conditie:=true;
end;


procedure inlocuieste(nr:longint);
var ind,ind2:longint;
begin
ind:=nr mod 200000;
ind2:=nr div 200000;
nr:=1 shl ind2;
v[ind]:=v[ind] or nr;
end;

begin
assign(f,'multiplu.in'); reset(f);
readln(f,a,b);
close(f);
x:=a*b;
while a<>b do
	if a>b then
  	a:=a-b
  else
  	b:=b-a;
x:=x div a;
new(cap);
cap^.cif:=true; cap^.dupa:=nil; cap^.inainte:=nil; cap^.rest:=1;
p:=cap; new(d); d:=cap;
ok:=false;
v[1]:=1;
while not ok do begin
  new(c);
  c^.cif:=false;
{  d^.dupa:=c; }
  c^.dupa:=nil; c^.inainte:=p;
  c^.rest:=(p^.rest*10) mod x;
  if conditie(c^.rest) then
		begin
  	{v[c^.rest]:=true; }
    inlocuieste(c^.rest);
  	d^.dupa:=c;
  	if c^.rest=0 then begin
  									  ok:=true;
                      gasit:=c;
                      end
  	else begin
  	     new(d);
         d^.cif:=true;
         c^.dupa:=d;
         d^.dupa:=nil; d^.inainte:=p;
  		   d^.rest:=(c^.rest+1) mod x;
         if d^.rest=0 then begin
       									   ok:=true;
                           gasit:=d;
                           end
         else p:=p^.dupa
         end
    end
  else begin
	     dispose(c);
       p:=p^.dupa
       end
end;
p:=gasit;
m:='';
while p^.inainte<>nil do begin
	if p^.cif then
    m:='1'+m
  else
  	m:='0'+m;
  p:=p^.inainte
end;
m:='1'+m;
assign(f,'multiplu.out'); rewrite(f);
writeln(f,m);
close(f);
end.