Title: Give a string of N (n<=1e6), the multiplicative and modulo 1,000,000,007 of the NUM array, where NUM (i) ={the number of strings s ' in the prefix of length I, where S ' is both the prefix of the prefix and the suffix of the prefix, And the suffix does not overlap with the prefix}
The topic background has been paved, the problem can be solved with KMP.
In calculating the NXT array, we can calculate the CNT array (skipping a few times to 0), indicating how many prefixes can match the suffix contained in the current prefix, for example, Niconiconi in this string, NXT (=6,NXT) (6) =2,nxt (2) = 0, So CNT (10) =3.3 prefixes representing a length of ten (Niconiconi)/6 (Niconi)/2 (NI) can be found with a suffix in the prefix length of 10 to match.
The CNT array is not a num array, because there will be strings that do not satisfy the criteria, so again the match will not satisfy the condition of the removal, that is, to meet the fix (already matched prefix length) < I (the length of the current prefix), at this time the statistical answer can be.
#include <cstdio> #include <cstring> #define N 1000005 #define MOD 1000000007 using
namespace Std;
typedef long Long LL;
Char S[n];
int nxt[n],cnt[n];
LL KMP () {memset (nxt,0,sizeof nxt); LL Ans=1;
Cnt[1]=1;
int Len=strlen (s+1), fix=0;
for (int i=2;i<=len;i++) {while (s[i]!=s[fix+1] && fix) Fix=nxt[fix];
if (s[i]==s[fix+1]) fix++;
Nxt[i]=fix;
cnt[i]=cnt[fix]+1;
} fix=0;
for (int i=2;i<=len;i++) {while (s[i]!=s[fix+1] && fix) Fix=nxt[fix];
if (s[i]==s[fix+1]) fix++;
while (Fix*2>i) Fix=nxt[fix];
ans*=cnt[fix]+1;
Ans%=mod;
} return ans;
} int main () {int T;
scanf ("%d", &t);
while (t--) scanf ("%s", s+1), printf ("%lld\n", KMP ());
return 0; }