#include #include #include typedef long long int int64; #define MAX(a,b) ((a)>(b)?(a):(b)) #define MIN(a,b) ((a)<(b)?(a):(b)) #define ABS(a) ((a)>(0)?(a):-(a)) void run(void){ char *s=(char *)malloc(sizeof(char)*(10000+1)); scanf("%s",s); int m; scanf("%d",&m); int *now=(int *)calloc(m,sizeof(int)); int *next=(int *)calloc(m,sizeof(int)); int cnt=0; const int mod=1000000007; int n; for(n=0;s[n]!='\0';n++){ int d=s[n]-'0'; int j; for(j=0;j=mod?t-mod:t; t=next[(10*j+d)%m]+now[j]; next[(10*j+d)%m]=t>=mod?t-mod:t; } if(d==0){ cnt++; } else{ next[d%m]=next[d%m]==mod-1?0:next[d%m]+1; } int *swap=now; now=next; next=swap; } printf("%d\n",(now[0]+cnt)%mod); } int main(void){ run(); return 0; }