#K46232. Largest Repeated Substring Length
Largest Repeated Substring Length
Largest Repeated Substring Length
Given a non-empty string s, determine the length of the smallest substring t that, when repeated consecutively, forms s. Formally, find the smallest positive integer l such that s = t^(n/l), where n is the length of s and t is the prefix of s with length l. If no such t exists with l < n, then the answer is n. For example:
- If
s = "abab"
, thent = "ab"
and the answer is 2. - If
s = "aaaa"
, thent = "a"
and the answer is 1. - If
s = "abcdef"
, no proper substring can be repeated to forms
, so the answer is 6.
This problem can be mathematically represented as finding the smallest integer \(l\) (where \(1 \leq l \leq n\)) satisfying \(n \bmod l = 0\) and \(s = t^{(n/l)}\), with t being s's prefix of length \(l\). If there is no such \(l\) with \(l < n\), then output \(n\).
inputFormat
The input consists of a single line containing a non-empty string s (with \(1 \leq |s| \leq 10^5\)).
outputFormat
Output a single integer denoting the length of the smallest substring that can be repeated to form the string s.
## sampleabab
2