Cod sursa(job #126494)

Utilizator Adrian001Vladulescu Adrian Adrian001 Data 22 ianuarie 2008 12:56:37
Problema Multiplu Scor 10
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.47 kb
Type stiva=array[1..100] of shortint;
var f,g:text;
    st:stiva;
    as,ev:boolean;
    n,i,ok,a,b,k:longint;

procedure init(var st:stiva;k:integer);
Begin
If k=1 then st[k]:=0
       else st[k]:=-1;
end;

procedure succesor(var as:boolean;var st:stiva;k:integer);
Begin
If st[k]<1 then Begin
                 st[k]:=st[k]+1;
                 as:=true;
                end
           else as:=false;
end;

{procedure valid(var ev:boolean;st:stiva;k:integer);
var nr:longint;
Begin
ev:=true;
nr:=0;
For i:=1 to k do nr:=nr*10+st[i];
If (nr mod a<>0) or (nr mod b<>0) then ev:=false;
end;}

function solutie(k:integer):boolean;
Begin
solutie:=(k=n);
end;

procedure tipar;
var nr:longint;
Begin
nr:=0;
If ok=1 then inc(ok);
For i:=1 to k do nr:=nr*10+st[i];
 If (nr mod a=0) and (nr mod b=0) then inc(ok);
If ok=1 then For i:=1 to n do Write(g,st[i]);
end;

Begin
Assign(f,'multiplu.in');Reset(f);
Assign(g,'multiplu.out');Rewrite(g);
Readln(f,a,b);
n:=2;
ok:=0;
While (n<=9) and (ok=0) do
 Begin
  k:=1;
  init(st,k);
  While k>0 do
   Begin
    {repeat}
     succesor(as,st,k);
     {If as then valid(ev,st,k);
     until (not as) or (as and ev); }
    If as then If solutie(k) then tipar
                             else Begin
                                   k:=k+1;
                                   init(st,k);
                                  end
          else k:=k-1;
   end;
  n:=n+1;
 end;
Close(f);
Close(g);
end.