Cod sursa(job #7290)

Utilizator alextheroTandrau Alexandru alexthero Data 21 ianuarie 2007 13:20:03
Problema Diviz Scor 0
Compilator cpp Status done
Runda preONI 2007, Runda 1, Clasele 11-12 Marime 0.81 kb
#include <stdio.h>
#define nmax 256
#define modulo 30103

int x[nmax];
int k,a,b;
int c[nmax][nmax];
char ch;

char c1[nmax][nmax][10];


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

    scanf("%d %d %d\n",&k,&a,&b);
    scanf("%c",&ch);
    while(ch>='0' && ch<='9') {
        x[++x[0]]=(int)(ch-'0');
        scanf("%c",&ch);
    }
    c[0][0]=1;
    for(int i=1;i<=x[0];i++) {
        int px=0;
        if(x[i]==0) px++;
        for(int j=b;j>=px;j--) 
            for(int l=k-1;l>=0;l--) {
                        c[j+1][(l*10+x[i])%k]+=c[j][l];
                        c[j+1][(l*10+x[i])%k]%=modulo;
            }
    }
    int x=0;
    for(int i=a;i<=b;i++) {
        x+=c[i][0];
        x%=modulo;
    }
    printf("%d\n",x);
    return 0;
}