1 #include2 #include 3 char s[105]; 4 int ans[105],temp[105],temp1[105][105],a[105][105]; 5 int main() 6 { 7 int i,j,k,n,m; 8 while (~scanf("%d",&m)) 9 {10 getchar();11 gets(s); n=strlen(s);12 for (i=1;i<=n;i++) ans[i]=s[i-1]-'0';13 memset(a,0,sizeof(a));14 for (i=1;i<=n;i++)15 if (i!=n) a[i][i]=a[i][i+1]=1;16 else a[i][1]=a[i][n]=1;17 while (m!=0)18 {19 if (m%2==1)20 {21 for (j=1;j<=n;j++)22 {23 temp[j]=0;24 for (i=1;i<=n;i++) temp[j]=(temp[j]+ans[i]*a[i][j])%2;25 }26 for (i=1;i<=n;i++) ans[i]=temp[i];27 }28 m/=2;29 {30 memset(temp1,0,sizeof(temp1));31 for (i=1;i<=n;i++)32 for (j=1;j<=n;j++)33 {34 for (k=1;k<=n;k++)35 temp1[i][j]=(temp1[i][j]+a[i][k]*a[k][j])%2;36 }37 for (i=1;i<=n;i++)38 for (j=1;j<=n;j++) a[i][j]=temp1[i][j];39 }40 }41 for (i=1;i<=n;i++) printf("%d",ans[i]);42 printf("\n");43 } 44 }