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 Rust (1.15.1) (judge verdict: Accepted)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use competitive::prelude::*;
use competitive::prime::divisors;

fn main() {
    input! {
        n: i64,
    }

    // for k in 2..=n {
    //     let mut t = n;
    //     while t % k == 0 {
    //         t /= k;
    //     }
    //     if t % k == 1 {
    //         dbg!(k);
    //     }
    // }

    let mut ss = BTreeSet::new();
    ss.insert(2);
    if n - 1 >= 2 {
        ss.insert(n - 1);
    }

    let test = |k: usize| -> bool {
        if k == 1 {
            return false;
        }
        let mut t = n as usize;
        while t % k == 0 {
            t /= k;
        }
        t % k == 1
    };

    let ds = divisors(n as usize);
    for d in ds {
        if test(d) {
            ss.insert(d as i64);
        }
    }

    let ds = divisors((n - 1) as usize);
    for d in ds {
        if test(d) {
            ss.insert(d as i64);
        }
    }

    let ans = ss.len();
    echo!(ans);
}
*/

fn main() {
    let exe = "/tmp/binCC61DC05";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";