Update include.hh
This commit is contained in:
parent
d2207f6446
commit
9df9b5de3c
10
include.hh
10
include.hh
|
@ -136,4 +136,14 @@ vector<int> kmp(string s, string t) { // find all t in s
|
|||
}
|
||||
return v;
|
||||
}
|
||||
int period(string s) { // find the length of shortest recurring period
|
||||
int n = s.length();
|
||||
auto z = calc_z(s);
|
||||
for (int i = 1; i <= n / 2; ++i) {
|
||||
if (n % i == 0 && z[i] == n - i) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
/////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue