Cod sursa(job #115533)

Utilizator runnaway90Oprescu Radu Constantin runnaway90 Data 16 decembrie 2007 12:56:28
Problema Multiplu Scor 10
Compilator fpc Status done
Runda preONI 2008, Runda 2, Clasa a 10-a Marime 1.33 kb
type vector=array[0..100000]of shortint;

var f:text;
        p,a,b,r,j,t,i:longint;
        ok:boolean;
        c:vector;

begin
        assign(f,'multiplu.in');
        reset(f);
                read(f,a,b);
        close(f);
        if a>b then
           p:=a
        else
           p:=b;
        ok:=true;
        while p<>0 do
        begin
                inc(r);
                p:=p div 10;

        end;

        for i:=1 to r-1 do
        c[i]:=0;

        c[r]:=1;

        c[0]:=r;


        ok:=true;
        while ok do
        begin
                j:=1;
             c[j]:=c[j]+1;
             while c[j]>1 do
             begin
                c[j]:=0;
                c[j+1]:=c[j+1]+1;
                j:=j+1;
             end;
             if j>c[0] then
             c[0]:=j;
              t:=0;
              for i:=c[0] downto 1 do
                t:=(t*10+c[i]) mod b;
              if t=0 then
              begin
                t:=0;
                for i:=c[0] downto 1 do
                   t:=(t*10+c[i]) mod a;
                if t=0 then
                        ok:=false;
              end;
        end;
        assign(f,'multiplu.out');
        rewrite(f);
                for i:=c[0] downto 1 do
                        write(f,c[i]);

        close(f);
end.