随便dp一下就好了。。。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 300050 #define maxm 1000050 #define mod 1000000007 using namespace std; long long n,m,t[maxn],sum[maxm],dp[maxn]; char s[maxn]; int main() { scanf("%lld%lld",&n,&m); scanf("%s",s); dp[0]=sum[0]=1; for (long long i=1;i<=n;i++) t[i]=(t[i-1]*10+s[i-1]-'0')%m; for (long long i=1;i<=n;i++) { dp[i]=sum[t[i]]; sum[t[i]]=(sum[t[i]]*2)%mod; } printf("%lld\n",dp[n]%mod); return 0; }