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
    if nn = 2 then Printf.printf "%d\n" 1 else
        let set = divisors (nn - 1) in
        let set = S.union (divisors nn) set in
        loop2 0 (S.elements set) |> Printf.printf "%d\n"
)