Problem:
Score : 600 points

Problem Statement

Given is a positive integer N.

We will choose an integer K between 2 and N (inclusive), then we will repeat the operation below until N becomes less than K.

Operation: if K divides N, replace N with N/K; otherwise, replace N with N-K.

In how many choices of K will N become 1 in the end?

Constraints

2 \leq N \leq 10^{12}

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the number of choices of K in which N becomes 1 in the end.

Sample Input 1

6

Sample Output 1

3

There are three choices of K in which N becomes 1 in the end: 2, 5, and 6.

In each of these choices, N will change as follows:

When K=2: 6 \to 3 \to 1

When K=5: 6 \to 1

When K=6: 6 \to 1

Sample Input 2

3141

Sample Output 2

13

Sample Input 3

314159265358

Sample Output 3

9

Solution in OCaml (4.02.3) (judge verdict: Time Limit Exceeded)

module S = Set.Make (struct type t = int let compare = compare end) ;;

Scanf.scanf "%d" (fun nn ->
    let divisors a =
        let rec loop i acc =
            if i * i > a then acc else
                let acc = if a mod i = 0 then S.add (a / i) (S.add i acc) else acc in
                loop (i + 1) acc
        in
        loop 2 (S.singleton a)
    in
    let rec loop n k =
        if n = 1 then true else
            if n < k then false else
            if n mod k = 0 then loop (n / k) k
                           else loop (n mod k) k
    in
    let rec loop2 acc = function
        | [] -> acc
        | hd :: tl ->
                let acc = if loop nn hd then acc + 1 else acc in
                loop2 acc tl
    in
    let set = divisors (nn - 1) in
    let set = S.union (divisors nn) set in
    loop2 0 (S.elements set) |> Printf.printf "%d\n"
)