Cod sursa(job #44691)

Utilizator ben_henryRuben Fagadar ben_henry Data 31 martie 2007 17:13:24
Problema Diviz Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.09 kb
program diviz;
var l:array[1..200] of integer;
    first:array[0..9] of array[0..200] of integer;
    c:array[1..200]of array [0..200]of array [0..100] of longint;
    cif,k,a,b,n,i,j,r:integer;
    s:longint;
    sir:string;
    f:text;
begin
assign(f,'diviz.in'); reset(f);
readln(f,k,a,b);
readln(f,sir);
n:=length(sir);
for i:=1 to n do val(sir[i],l[i],j);
close(f);
for cif:=0 to 9 do begin
    j:=0;
    for i:=n downto 0 do begin
        first[cif][i]:=j;
        if l[i]=cif then j:=i;
    end;
end;
for j:=1 to n do for i:=1 to n do for r:=0 to k-1 do c[j][i][r]:=0;
for cif:=1 to 9 do c[1][first[cif][0]][cif mod k]:=1;
s:=0;
for j:=1 to n do
    for i:=j to n do
        for r:=0 to k-1 do begin
          for cif:=0 to 9 do
                if not ((c[j][i][r]=0) and (cif=0)) then inc(c[j+1][first[cif][i+1]][(r*10+cif) mod k]);
          if (r=0) and (a<=j) and (j<=b) and (c[j][i][r]<>0) then begin
                s:=s+c[j][i][r];
                s:=s mod 30103;
          end;
        end;
assign(f,'diviz.out'); rewrite(f);
s:=s+1;
writeln(f,s);
close(f);
end.