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:
/*
#![allow(unused_mut)]
#![allow(bare_trait_objects)]
#![allow(unused_imports)]
#![allow(unused_macros)]
// #![allow(dead_code)]

// https://github.com/tanzaku/rust-procon-lib
#[macro_use]
extern crate rust_procon_lib;

use rust_procon_lib::modcomb::*;
use rust_procon_lib::modint::*;
use rust_procon_lib::scanner::*;
use rust_procon_lib::tree::*;

// make_modint!(MOD_1000000007);
// make_modcomb!();

fn main() {
    let mut sc = Scanner::from_stdin();

    // k^i * x, x % k == 1
    let n = sc.i64();

    if n == 2 {
        println!("{}", 1);
        return;
    }

    let f = |n: i64, i: i64| {
        let mut x = n;
        while x % i == 0 {
            x /= i;
        }
        x % i == 1
    };

    let mut ans = 2;
    for i in 2.. {
        // if f(n, i) {
        // if n % i == 0 || (n - 1) % i == 0 {
        //     ans += 1;
        //     eprintln!("{} {} {}", i, n % i, (n - 1) % i);
        // }
        // if f(n, i) {
        //     eprintln!("{}", i);
        // }
        // if n % i == 0 && i * i != n && f(n, n / i) {
        //     ans += 1;
        // }
        if i * i > n - 1 {
            break;
        }
        if (n - 1) % i == 0 {
            ans += 1;
            // eprintln!("{} {}", i, (n - 1) % i);
            if (n - 1) != i * i {
                ans += 1;
                // eprintln!("{} {}", i, (n - 1) % ((n - 1) / i));
            }
        }
    }
    for i in 2.. {
        if i * i > n {
            break;
        }
        if (n - 1) % i != 0 && f(n, i) {
            ans += 1;
            // eprintln!("{} {}", i, n % i);
        }
    }
    // for i in 2.. {
    //     // if (n - 1) % i == 0 {
    //     //     ans += 1;
    //     // }
    //     // if i * i > n - 1 {
    //     //     break;
    //     // }
    // }
    // let mut i = n - 1;
    // while i * i > n && i % {
    //     i /= 2
    // }
    println!("{}", ans);
}
*/

fn main() {
    let exe = "/tmp/binFA2C25D6";
    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>";