Cod sursa(job #17990)

Utilizator sims_glAlexandru Simion sims_gl Data 17 februarie 2007 18:28:45
Problema Diviz Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <stdio.h>
#include <string.h>

#define lm 210
#define km 110
#define mod 30103

int k, a, b, m, last[lm][km], crt[lm][km], x[lm][km][10], sol, used[10];
char n[lm];

int main()
{
	int step, i, j;

	freopen("diviz.in", "r", stdin);
    freopen("diviz.out", "w", stdout);

    scanf("%d%d%d", &k, &a, &b);
    scanf(" %s ", &n);

    m = strlen(n);

    for (step = 0; step < m; ++step)
    {
    	for (i = m; i > 0; --i)
            for (j = 0; j < k; ++j)
            {
            	crt[i + 1][(j * 10 + n[step] - '0') % k] = (crt[i + 1][(j * 10 + n[step] - '0') % k] + last[i][j] - x[i][j][n[step] - '0']) % mod;
            	x[i][j][n[step] - '0'] = last[i][j];
            }
            
        if (n[step] != '0')
        {
            if (!used[n[step] - '0'])
		        ++crt[1][(n[step] - '0') % k];

            used[n[step] - '0'] = 1;
        }
        
    	for (i = m; i > 0; --i)
            for (j = 0; j < k; ++j)
				last[i][j] = (last[i][j] + crt[i][j]) % mod,
                crt[i][j] = 0;
    }

    for (i = a; i <= b; ++i)
    	sol = (sol + last[i][0]) % mod;

    printf("%d\n", sol);

	return 0;
}