Pagini recente » Cod sursa (job #2253651) | Cod sursa (job #2146813) | Sandbox (cutiuţa cu năsip) | Cod sursa (job #2678022) | Cod sursa (job #1553739)
#include <stdio.h>
#include <string.h>
#define MAXK 100
#define MAXN 200
#define MOD 30103
int d[2][MAXN+1][MAXK], k, v[MAXN+1], next[MAXN+1][10];
int main(){
int a, b, n, k, ans, i, j, x, r, cif;
char ch;
FILE *fin, *fout;
fin=fopen("diviz.in", "r");
fout=fopen("diviz.out", "w");
fscanf(fin, "%d%d%d ", &k, &a, &b);
n=0;
ch=fgetc(fin);
while(ch!='\n'){
v[++n]=ch-'0';
ch=fgetc(fin);
}
ans=0;
for(i=n-1; i>=0; i--){
for(j=0; j<10; j++){
next[i][j]=next[i+1][j];
}
next[i][v[i+1]]=i+1;
}
for(i=1; i<=9; i++){
d[1][next[0][i]][i%k]++;
}
ans=0;
for(i=1; i<=b; i++){
if(a<=i){
for(j=1; j<=n; j++){
ans+=d[i&1][j][0];
}
ans%=MOD;
}
if(i<b){
memset(d[(i+1)&1], 0, sizeof d[(i+1)&1]);
for(j=1; j<=n; j++){
x=0;
for(r=0; r<k; r++){
if(d[i&1][j][r]){
x=10*r;
while(x>=k){
x-=k;
}
for(cif=0; cif<10; cif++){
d[(i+1)&1][next[j][cif]][x]+=d[i&1][j][r];
if(d[(i+1)&1][next[j][cif]][x]>=MOD){
d[(i+1)&1][next[j][cif]][x]-=MOD;
}
x++;
if(x>=k){
x-=k;
}
}
}
}
}
}
}
fprintf(fout, "%d\n", ans);
fclose(fin);
fclose(fout);
return 0;
}