如果两个相邻的串可行,那么它们合并后一定可行,所以求出所有可行的串的个数$t$,则$ans=2^{t-1}$。

注意特判整个串不可行的情况,这个时候答案为0。

 

#include<cstdio>
int n,m,i,t,ans;char a[300010];
int main(){
  for(scanf("%d%d%s",&n,&m,a);i<n;i++){
    t=(t*10+a[i]-'0')%m;
    if(!t)if(!ans)ans=1;else ans=ans*2%1000000007;
  }
  return printf("%d",t?0:ans),0;
}

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-17
  • 2021-10-15
  • 2021-07-19
猜你喜欢
  • 2022-02-11
  • 2021-09-26
  • 2021-06-18
  • 2022-01-03
  • 2021-10-03
  • 2021-06-17
  • 2021-08-25
相关资源
相似解决方案