Pagini recente » Cod sursa (job #1306082) | Cod sursa (job #1290573) | Cod sursa (job #94791) | Istoria paginii runda/simulare-juniori-8-oji | Cod sursa (job #139008)
Cod sursa(job #139008)
#include<stdio.h>
#include<string.h>
#define maxn (1<<8)
long k,a,b;
char sir[maxn];
unsigned short int v[2][maxn][maxn];
long next[maxn][16];
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( long cif = 0; cif <= 9; ++cif)
{
long max = n+1;
for(long 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;
}
}
long sol =0;
for( long l2 = 1; l2 <= b; ++l2)
{
long l = l2%2;
long l3 = (l+1)%2;
for( long i = 0; i < n; ++i)
{
for( long 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( long cif = 0; cif <= 9; ++cif)
{
long aux = next[i][cif];
if( aux == n+1) continue;
long 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;
}