Pagini recente » Cod sursa (job #1722801) | Cod sursa (job #2708262) | Cod sursa (job #2317282) | Cod sursa (job #1100775) | Cod sursa (job #47498)
Cod sursa(job #47498)
# include <stdio.h>
# include <string.h>
# define _fin "diviz.in"
# define _fout "diviz.out"
# define maxn 202
# define maxk 101
# define mod 30103
int n[maxn], k, a, b,
m[2][maxn][maxk], act,
f[maxn][10], cr[10],
i, j, r, cif, sol, tr;
char buf[maxn];
void readf()
{
freopen(_fin, "r", stdin);
scanf("%d%d%d\n%s", &k, &a, &b, buf);
for (n[0]=strlen(buf), i=0; i<n[0]; i++) n[i+1]=buf[i]-0x30;
}
void solve()
{
for (i=0; i<=9; i++) cr[i]=-1;
for (i=n[0]; i>=0; i--) {
if ( i>0 ) cr[ n[i] ]=i;
for (j=0; j<=9; j++) f[i][j]=cr[j];
}
for (j=0; j<=9; j++) f[n[0]+1][j]=-1;
for (i=1; i<=9; i++)
if ( f[0][i]!=-1 ) {
m[0][ f[0][i] ][i%k]=1;
if ( !(i%k) && a==1 ) ++sol;
}
for (i=1; i<=b; i++) {
for (j=i; j<=n[0]; j++)
for (r=0; r<k; r++)
if ( m[act][j][r] ) {
if ( !r && i>=a ) {
sol += m[act][j][r];
if ( sol>=mod ) sol -= mod;
}
if ( j==n[0] ) continue;
for (cif=0; cif<=9; cif++)
if ( f[j+1][cif] != -1 ) {
m[!act][f[j+1][cif]][ tr=((r*10+cif)%k) ] += m[act][j][r];
if ( m[!act][f[j+1][cif]][tr] >= mod )
m[!act][f[j+1][cif]][tr] -= mod;
}
}
act=!act;
memset(m[!act], 0, sizeof(m[!act]));
}
}
int main()
{
readf();
freopen("debug.txt", "w", stdout);
solve();
fprintf(fopen(_fout,"w"), "%d\n", sol);
return 0;
}