Under construction

Still being built. Things may change

Sequences without Stammers

Time limit3sMemory limit128 MB

Summary
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 x1,x2,…,xnx_1, x_2, \dots, x_n contains a stammer if some block of consecutive letters is immediately followed by an identical block. Formally, there exist indices ii and jj with 1≤i<j1 \le i < j and 2j−i−1≤n2j - i - 1 \le n such that

xi=xj,  xi+1=xj+1,  …,  xj−1=x2j−i−1.x_{i} = x_{j},\; x_{i+1} = x_{j+1},\; \dots,\; x_{j-1} = x_{2j-i-1}.

Equivalently, the sequence contains a square: a factor of the form wwww for some non-empty word ww. A sequence with no such repeated block is called stammer-free.

We want to build a stammer-free sequence of length nn using as few distinct letters as possible.

Some observations:

  • With a single letter, the only stammer-free sequences have length 11, because aaaa is already a stammer.
  • With two letters, say aa and bb, the longest stammer-free sequences have length 33: exactly abaaba and babbab. For example, bababbabab is not stammer-free (the block baba and the block abab each repeat).
  • With three letters, a stammer-free sequence exists for every length; for instance abcababcab is a stammer-free sequence of length 55.

Determine the minimal number of different letters needed.

Input

The first line of standard input contains one positive integer nn (1≤n≤10,000,0001 \le n \le 10{,}000{,}000) — the desired length of the sequence.

Output

Print a single positive integer kk: the minimal number of distinct letters that must appear in any stammer-free sequence of length nn.

Examples5

  1. Example 1

    Input
    1
    
    Expected output
    1
    
  2. Example 2

    Input
    2
    
    Expected output
    2
    
  3. Example 3

    Input
    3
    
    Expected output
    2
    
  4. Example 4

    Input
    4
    
    Expected output
    3
    
  5. Example 5

    Input
    5
    
    Expected output
    3