Pagini recente » Cod sursa (job #869596) | Cod sursa (job #1588321) | Cod sursa (job #3191900) | Cod sursa (job #2158279) | Cod sursa (job #219617)
Cod sursa(job #219617)
#include <stdio.h>
#include <string.h>
#define maxn (1<<8)
long k, a, b, next[maxn][16], cif, max, i, sol, l2, l, l3, j, aux, aux2, v[2][maxn][maxn];
char sir[maxn];
int main() {
freopen("diviz.in", "r", stdin);
freopen("diviz.out", "w", stdout);
scanf("%ld %ld %ld", &k, &a, &b);
scanf("%s", sir);
long n = strlen(sir);
for (cif = 0; cif <= 9; ++cif) {
max = n + 1;
for (i = n; i >= 0; --i) {
next[i][cif] = max;
if (sir[i] - '0' == cif) {
max = i;
}
}
if (max != n + 1 && cif != 0) {
v[1][max][cif % k] = 1;
}
}
sol = 0;
for (l2 = 1; l2 <= b; ++l2) {
l = l2 % 2;
l3 = (l + 1) % 2;
for (i = 0; i < n; ++i) {
for (j = 0; j < k; ++j) {
if (v[l][i][j] == 0) continue;
if (l2 >= a && l2 <= b && j == 0) {
sol += v[l][i][j];
if (sol >= 30103) {
sol -= 30103;
}
}
if (l == b) continue;
for (cif = 0; cif <= 9; ++cif) {
aux = next[i][cif];
if (aux == n + 1) continue;
aux2 = j * 10 + cif;
while (aux2 >= k) {
aux2 -= k;
}
v[l3][aux][aux2] += v[l][i][j];
if (v[l3][aux][aux2] >= 30103) {
v[l3][aux][aux2] -= 30103;
}
}
v[l][i][j] = 0;
}
}
}
printf("%ld\n", sol);
return 0;
}