Pagini recente » Cod sursa (job #29928) | Cod sursa (job #2530189) | Cod sursa (job #1515518) | Cod sursa (job #750376) | Cod sursa (job #219224)
Cod sursa(job #219224)
#include <stdio.h>
#include <string.h>
#define MAX_N 256
#define MAX_K 128
#define MOD 30103
int K, A, B, L, C[MAX_N][MAX_N][MAX_K], S[MAX_N][10], N[MAX_N];
void process(void)
{
int i, T[10];
memset(T, 0xff, sizeof(T));
for (i = L - 1; i >= 0; i--)
{
memcpy(S[i], T, sizeof(int) * 10);
T[N[i]] = i;
}
}
int main(void)
{
int i, j, k, d, sols = 0;
char str[MAX_N];
freopen("diviz.in", "r", stdin);
freopen("diviz.out", "w", stdout);
scanf("%d %d %d\n", &K, &A, &B);
scanf("%s", str), L = strlen(str);
for (i = 0; i < L; i++)
N[i] = str[i] - '0';;
process();
for (i = 0; i < 10; i++)
if (S[0][i] >= 0 && i != N[0])
C[S[0][i]][1][i % K] = 1;
C[0][1][N[0] % K] = 1;
for (i = 0; i < L; i++)
for (j = 1; j <= L; j++)
for (k = 0; k < K; k++)
{
if (!C[i][j][k])
continue;
if (A <= j && j <= B && k == 0)
sols = (sols + C[i][j][k]) % MOD;
for (d = 0; d < 10; d++)
if (S[i][d] > 0)
C[S[i][d]][j + 1][(k * 10 + d) % K] =
(C[S[i][d]][j + 1][(k * 10 + d) % K] + C[i][j][k]) % MOD;
}
printf("%d\n", sols);
return 0;
}