Sequences without Stammers
Time limit3sMemory limit128 MB
Print the smallest alphabet size for which a square-free (stammer-free) string of length n exists.
- Level
Easy3 of 10
- Topics
- String, Combinatorics, Math
- Solved
- No attempts yet
Problem
We work with sequences of letters. A sequence contains a stammer if some block of consecutive letters is immediately followed by an identical block. Formally, there exist indices and with and such that
Equivalently, the sequence contains a square: a factor of the form for some non-empty word . A sequence with no such repeated block is called stammer-free.
We want to build a stammer-free sequence of length using as few distinct letters as possible.
Some observations:
- With a single letter, the only stammer-free sequences have length , because is already a stammer.
- With two letters, say and , the longest stammer-free sequences have length : exactly and . For example, is not stammer-free (the block and the block each repeat).
- With three letters, a stammer-free sequence exists for every length; for instance is a stammer-free sequence of length .
Determine the minimal number of different letters needed.
Input
The first line of standard input contains one positive integer () — the desired length of the sequence.
Output
Print a single positive integer : the minimal number of distinct letters that must appear in any stammer-free sequence of length .