Editorial Let $$$ fi (s) $$$ be a function of the string $$$ s $$$ equal to $$$ 1 $$$ if…
- User
Editorial
Let be a function of the string equal to if the prefix and suffix of length are equal, and equal to otherwise. We need to calculate (using linearity of expectation) . We will call the number the period of the string if for all . Moreover, the length of is not required to be divided by . ** Statement 1: ** is the period of the string is . ** Proof: ** that is equivalent to , which is equivalent to the fact that for from to . ** Statement 2: ** . ** Proof: ** The probability that is , since each of the last characters is uniquely determined from the previous ones. ** Statement 3: ** Let . Then . ** Proof: ** Assume that . We know that the string is and -periodic. Consider a graph of string positions, and draw edges between positions at distances . Then the number of different strings satisfying is , where is the number of connected components of our graph. Then . Thus, we need to show that . The case of is obvious: in this case, by subtracting and adding we can show that the string has period , in this case . We now consider the case when . Without loss of generality, . We write out in a circle numbers from to . They denote the components of connectivity when we draw only the edges connecting the positions at a distance of . Now we need to add edges of the form for (here ). Moreover, we know that . We will add these edges one at a time and observe how the connected components change. If we connected two positions that were not connected yet, then we reduced the number of connected components by . Otherwise, we connected two already connected vertices and formed a cycle. When does a cycle form at all? If we consider all the edges of the form , then our graph is divided into cycles - components, each of which contains all positions giving the same residues when divided by . Thus, it is necessary to calculate how many of these cycles we form. If cycles are formed, then the number of components will be . How many cycles will we create? Let's see if the cycle consisting of positions giving the remainder when divided by closes. It closes only if all its vertices are in . This is equivalent to the fact that among the positions in , not a single number gives the remainder of when dividing by . If , then this cannot happen for any , , and . Otherwise, there will be exactly , where . Thus, the statement is proved. Further reasoning is standard. We have shown that depends only on and . It remains for to count the number of pairs such that , , . We will do it as follows: if , , , then we rewrite it as , , . Now we just need to find the number of numbers coprime to on the segment . This can be done for , where is the number of prime divisors of . It can be shown that this gives the asymptotics of (If you have a better one, please share in the comments!)
Assistant