A
binary string
is a string whose characters are only
0
s and/or
1
s. For example,
are binary strings.
A string is periodic if there exists another string whose length is less than such that concatenating several copies of produces . For example, is periodic ( ), and is periodic ( or ), but is not periodic. A string is aperiodic if it is not periodic.
This problem asks about the number of aperiodic binary strings of length . For this problem, compute the number of aperiodic binary strings of length (that is, 23 factorial raised to the 23th power). Enter your answer modulo .
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Let's skip to the formal stuff immediately. For a gentler introduction, try the linked problem above.
First, definitions.
Now, the claim: the number of aperiodic strings of length n is
X ⊂ P ∑ ( − 1 ) ∣ S ∣ ⋅ 2 Π ( X ) n
To prove this is correct, we will begin with several simple observations about our S I 's.
Result 1 : If s is periodic with repeat count m , then m divides ∣ s ∣ .
Trivial; having m copies of a string means the total length is a multiple of m .
Result 2 : If s is periodic with repeat count m and d ∣ m , then s is periodic with repeat count d . If s is made up of building block t with repeat count m , then s is also made up of building block t ′ with repeat count d , where t ′ is t repeated d m times. The corollary uses the fact that Π ( A ) ∣ Π ( B ) .
Result 3 : S ∅ is precisely the set of all binary strings of length n .
Result 4 : If X = ∅ , S X only contains periodic binary strings (of length n ).
Trivial by definition.
Result 5 : Every periodic binary string (of length n ) is contained in S { d } for some d ∈ P . This follows from Result 2. Suppose s is periodic with repeat count m , and let d be one prime divisor of m (exists because m = 1 by definition of being periodic). Then s is also periodic with repeat count d . Since d is a prime number, it is also necessarily a prime divisor of n (Result 1), and this implies s ∈ S { d } .
Result 6 : If A , B ⊂ P , then S A ∩ S B = S A ∪ B .
This should be easy, but strangely I can't find a proof for this. I'll edit this later.
Result 7 : If A , B , C are sets such that B , C ⊂ A , then ∣ A ∖ ( B ∪ C ) ∣ = ∣ A ∖ C ∣ − ∣ B ∖ ( B ∩ C ) ∣ .
Straightforward: the first term removes all in C , the second term removes all in B that aren't in C and thus missed by the first term.
Result 8 : If X ⊂ P , then ∣ S X ∣ = 2 n / Π ( X ) .
Straightforward. All building blocks are of length Π ( X ) n (because they are repeated Π ( X ) times, and so we're counting binary strings of length Π ( X ) n .
Let A be our sought number. By Results 3, 4, 5, we have A = ∣ ∣ S ∅ ∖ ∪ d ∈ P S { d } ∣ ∣ . By Results 6 and 7, we can implement this effectively by recursion. (This is also the Principle of Inclusion-Exclusion.) The base case is just a single set (without anything subtracted from it), which Result 8 can handle. We can actually expand this recursion fully to show that it's equal to the claim above.
Handling ( 2 3 ! ) 2 3 is hard; we will denote our number in its prime factorization instead. Our number n will be represented as
[(f1,e1), (f2,e2), ...]
, which means n = f 1 e 1 f 2 e 2 … . The functionsfactorial
andfactorize
, along with the assignment tofactors
at the end, are just means to compute the factorization. (There should be a more efficient method on doing this, but I suppose this is the clearest. If necessary, you can sidestep it entirely by computing the expansion by hand, also to avoid having problems with finite precision integers.)triple_pow
computes a b c . Since our number is represented in its prime factorization, we will use this a lot. For example, computing 2 n becomes computing 2 f 1 e 1 f 2 e 2 … = ( ( 2 f 1 e 1 ) f 2 e 2 ) … . Of course, we apply modulo here, since we don't actually need to care about the result, just its value modulo 1 0 9 + 7 .solve
is the meat of the problem, which implements the recursion in Result 7 in a straightforward manner.Another method to compute A is possible in this manner, thanks to Challenge Master. Let A ( k ) be the number of aperiodic strings of length k . For every binary string of length n , there is a unique smallest building block, which is necessarily aperiodic; thus for every binary string of length n , we can map it to an aperiodic string. All aperiodic strings considered have lengths that divide n ; additionally, if d ∣ n and t is an aperiodic string of length d , then it has a unique pre-image to some string of length n (namely t repeated d n times). Thus we have the equality 2 n = ∑ d ∣ n A ( d ) : every binary string of length n is mapped uniquely to some aperiodic string of length that divides n , and all such aperiodic string has a pre-image. Using the Mobius inversion formula, we obtain A ( n ) = ∑ d ∣ n μ ( d ) 2 n / d . Since μ ( d ) = 0 if d is not square-free, the only terms that matter have d that is square-free, and thus we can map it to a subset X of prime divisors of n , where μ ( d ) = ( − 1 ) ∣ X ∣ and d = Π ( X ) ; this gives the same formula as above.