Pagini recente » Cod sursa (job #2057164) | Cod sursa (job #2105009) | Cod sursa (job #3216780) | Cod sursa (job #2286049) | Cod sursa (job #14861)
Cod sursa(job #14861)
#include <stdio.h>
#include <string.h>
#define maxn 210
#define maxx 110
#define maxl 10
#define mod 30103
int n,m,x,y,sol;
char a[maxn];
int b[maxn][maxl];
int c[maxn][maxx],d[maxn][maxx];
int main()
{
freopen("diviz.in","r",stdin);
freopen("diviz.out","w",stdout);
int i,j,k,p;
scanf("%d %d %d ",&m,&x,&y);
fgets(a,maxn,stdin);
n=strlen(a)-2;
for (i=0;i<maxl;i++) b[n][i]=n+1;
for (i=n-1;i>=0;i--)
for (j=0;j<maxl;j++)
if (a[i+1]-'0'!=j) b[i][j]=b[i+1][j];
else b[i][j]=i+1;
for (i=0;i<=n;i++)
if (a[i]!='0') c[i][(a[i]-'0')%m]=1;
for (i=1;i<=y;i++)
{
if (i>=x)
for (j=0;j<=n;j++)
{
sol+=c[j][0];
if (sol>mod) sol-=mod;
}
for (j=0;j<=n;j++)
for (k=0;k<m;k++)
{
d[j][k]=c[j][k];
c[j][k]=0;
}
for (j=0;j<=n;j++)
for (k=0;k<m;k++)
if (d[j][k]!=0)
for (p=0;p<maxl;p++)
if (b[j][p]!=n+1)
{
c[b[j][p]][(k*10+p)%m]+=d[j][k];
if (c[b[j][p]][(k*10+p)%m]>mod) c[b[j][p]][(k*10+p)%m]-=mod;
}
}
printf("%d\n",sol);
return 0;
}