标签:printf 变化 inpu 语句 output sam xmlns des www.
1 #include<cstdio> 2 using namespace std; 3 const int mo=1000000007; 4 int a,c,k,m,n,mx,ans,mi[1000010],f[1000010][17],g[1000010][17]; 5 char s[100010]; 6 int main() 7 { 8 freopen("zero.in","r",stdin); 9 freopen("zero.out","w",stdout); 10 scanf("%d%d%d%d%d",&a,&c,&k,&m,&n); 11 scanf("%s",s+1); 12 mi[0]=2; for (int i=1;i<=16;i++) mi[i]=(long long)mi[i-1]*mi[i-1]%mo; 13 for (int i=1;i<=n;i++) mx=((long long)mx*2+s[i]-‘0‘)%mo; 14 for (int i=0;i<m;i++) 15 { 16 int z=((long long)a*i+c)/k%m; 17 g[i][0]=z,f[i][0]=z<m/2?0:1; 18 } 19 for (int j=1;j<=16;j++) 20 for (int i=0;i<m;i++) 21 { 22 int z=g[i][j-1]; 23 f[i][j]=((long long)f[i][j-1]*mi[j-1]+f[z][j-1])%mo; 24 g[i][j]=g[z][j-1]; 25 } 26 for (int i=0;i<m;i++) 27 { 28 int t=i,l=0; 29 for (int j=n,u=0;j;j>>=1,u++) 30 if (j%2==1) 31 { 32 l=((long long)l*mi[u]+f[t][u])%mo; 33 t=g[t][u]; 34 } 35 if (l==mx) ans++; 36 } 37 printf("%d",ans); 38 return 0; 39 }
标签:printf 变化 inpu 语句 output sam xmlns des www.
原文地址:https://www.cnblogs.com/Comfortable/p/9649118.html