Pagini recente » Cod sursa (job #1202013) | Cod sursa (job #2778775) | Cod sursa (job #3235487) | Cod sursa (job #3218655) | Cod sursa (job #7301)
Cod sursa(job #7301)
const
lim=300;
base=30103;
var a:array [0..1,0..lim,0..lim] of longint;
rest,p,q,m,i,j,r,n,k,s,d:longint;
resturi:array[0..lim] of longint;
ultap:array[0..9,1..lim] of longint;
cif:array[1..lim]of longint;
c:char;
t:integer;
sol:longint;
procedure calculez_restu;
begin
rest:=cif[j] mod k;
for r:=1 to (i-1) do
rest:=(rest*10) mod k;
end;
begin
assign(input,'diviz.in');
reset(input);
readln(k,s,d);
i:=0;
while not seekeoln do
begin
read(c);
inc(i);
val(c,cif[i],t);
inc(a[0,i,cif[i] mod k]);
end;
m:=i;
sol:=0;
close(input);
if (s=1) and (k<10) then
for i:=1 to m do
if (cif[i]<>0) and ((cif[i] mod k)=0) then inc(sol);
for i:=m downto 1 do
for j:=0 to 9 do
if cif[i]=j
then ultap[j,i]:=i
else ultap[j,i]:=ultap[j,i+1];
p:=1;
q:=0;
for i:=2 to m do
begin
p:=1-p; {precedent}
q:=1-q; {curent}
fillchar(a[q],sizeof(a[q]),0);
for j:=(m-i+1) downto 1 do
begin
calculez_restu;
for t:=0 to 9 do
if ultap[t,j+1]<>0 then
for r:=0 to (k-1) do
a[q,j,(r+rest) mod k]:=(a[q,j,(r+rest) mod k]+a[p,ultap[t,j+1],r])mod base;
end;
if (s<=i) and (i<=d) then
begin
for t:=1 to 9 do sol:=(sol+a[q,ultap[t,1],0]) mod base;
end;
end;
assign(output,'diviz.out');
rewrite(output);
writeln(sol);
close(output);
end.