kmp复健,答案是n-next[n]
#include<iostream>
#include<cstdio>
using namespace std;
const int N=1000005;
int n,ne[N];
char s[N];
int main()
{
scanf("%d%s",&n,s+1);
int j=0;
for(int i=2;i<=n;i++)
{
while(s[j+1]!=s[i]&&j)
j=ne[j];
if(s[j+1]==s[i])
j++;
ne[i]=j;
}
printf("%d
",n-ne[n]);
return 0;
}