Pagini recente » Cod sursa (job #1039577) | Cod sursa (job #920733) | Cod sursa (job #2191767) | Cod sursa (job #2672504) | Cod sursa (job #27205)
Cod sursa(job #27205)
{$I-,Q-,R-,S-}
const
FIN = 'diviz.in';
FOUT = 'diviz.out';
NMAX = 200;
KMAX = 100;
CIFMAX = 10;
PRIM = 30103;
VAR
M : array[ 0..1,0..NMAX,0..KMAX ] of WORD;
V : array[ 1..NMAX ] of longint;
first : array[ 0..CIFMAX, 0..NMAX ] of longint;
f, g : text;
K, A, B, N : longint;
ans : word;
procedure read_data;
var i, cod : longint;
s : string;
begin
assign( f, FIN ); reset( f ); readln( f, K, A, B );
readln( f, s ); N := length( s );
for i := 1 to N do val( s[i], v[i], cod );
close( f );
end;
procedure add( var a, b : word ); inline;
begin
inc( a, b );
if a >= PRIM then dec( a, PRIM );
end;
procedure solve;
var i, j, cif, o, oo, r : word;
begin
for i := 0 to 9 do first[ i ][ N + 1 ] := - 1;
for i := N downto 1 do
for j := 0 to 9 do
if V[i] = j then first[j][i] := i
else first[j][i] := first[j][i+1];
// first[j][i] = prima aparitie a cifrei j pe pozitiile V[i], V[i+1]..V[N]
o := 0; oo := 1; ans := 0;
for i := 1 to 9 do
if first[i][1] <> - 1 then
begin
M[o][first[i][1]][ i mod k ] := 1;
if ( A = 1 ) and ( i mod k = 0 ) then inc( ans );
end;
for i := 1 to B do // lungimea subsirului
begin
fillchar( M[oo], sizeof( M[oo] ), 0 );
for j := i to N do // pozitia din sirul V
begin
if ( i >= A ) then add( ans, M[o][j][0] );
for r := 0 to K - 1 do // restul impartirii numarului la k
for cif := 0 to 9 do
if first[cif][j+1] <> - 1 then
add( M[oo][ first[cif][j+1]][ ( r * 10 + cif ) mod K ], M[o][j][r] );
end;
o := 1 - o;
oo := 1 - oo;
end;
end;
procedure save;
begin
assign( g, FOUT ); rewrite( g ); writeln( g, ans );
close( g) ;
end;
begin
read_data;
solve;
save;
end.