Pagini recente » Cod sursa (job #1155902) | Cod sursa (job #1785216) | Cod sursa (job #2339434) | Cod sursa (job #1727831) | Cod sursa (job #984002)
Cod sursa(job #984002)
#include <fstream>
#include <string.h>
#define NRM 30103
#define MAXN 205
#define MAXM 105
using namespace std;
ifstream f("diviz.in");
ofstream g("diviz.out");
int m,a,b,n,next[MAXN][15],x,pd[2][MAXN][MAXM],act,sol;
char s[MAXN];
int main(){
int i,j,k,ii;
f>>m>>a>>b;
f.getline(s+1,MAXN,'\n');
f.getline(s+1,MAXN,'\n');
n=strlen(s+1);
for(i=n;i>=1;i--){
x=s[i]-'0';
for(j=0;j<10;j++)
next[i][j]=next[i+1][j];
next[i][x]=i;}
for(i=1;i<10;i++)
if(next[1][i]){
x=next[1][i];
for(j=0;j<10;j++)
if(next[x+1][j])
pd[1][next[x+1][j]][(i*10+j)%m]++;
if(a==1&&i%m==0)
sol++;}
act=1;
for(k=2;k<=b;k++){
for(i=k-1;i<=n;i++){
for(j=0;j<m;j++){
if(k>=a){
sol+=pd[act][i][0];
while(sol>NRM)
sol-=NRM;}
if(pd[act][i][j]){
pd[act][i][j]%=NRM;
for(ii=0;ii<10;ii++)
if(next[i+1][ii])
pd[1-act][next[i+1][ii]][(j*10+ii)%m]+=pd[act][i][j];
pd[act][i][j]=0;}}}
act=1-act;}
g<<sol<<'\n';
f.close();
g.close();
return 0;}