P4349 [CERC2015] Digit Division
Genius_Star · · 题解
思路:
简单题,考虑找到可以分割的点的个数
注意到,每个区间都被
但是如果最后一个点是分割点的话,分割或者不分割是一样的,所以不算这个答案;无解的话是整个数字都不被
时间复杂度为
完整代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=300300,mod=1e9+7;
inline ll read(){
ll x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
if(c=='-')
f=-1;
c=getchar();
}
while(c>='0'&&c<='9'){
x=(x<<1)+(x<<3)+(c^48);
c=getchar();
}
return x*f;
}
inline void write(ll x){
if(x<0){
putchar('-');
x=-x;
}
if(x>9)
write(x/10);
putchar(x%10+'0');
}
ll n,m,sum,ans;
char c;
ll qpow(ll sum,ll b){
ll ans=1;
while(b){
if(b&1ll)
ans=(ans*sum)%mod;
sum=(sum*sum)%mod;
b>>=1ll;
}
return ans;
}
int main(){
n=read(),m=read();
for(int i=1;i<=n;i++){
scanf("%c",&c);
sum=(sum*10%m+c-'0')%m;
if(!sum)
ans++;
}
write(sum?0:qpow(2ll,ans-1));
return 0;
}