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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);
vector<ll> enum_div(ll);

// ================ Main Loop ================
int main() {
    ll n;
    cin >> n;
    vector<ll> tr1, tr2;
    set<ll> s;
    tr1 = enum_div(n);
    tr2 = enum_div(n - 1);
    for(auto v : tr1) {
        s.insert(v);
    }
    for(auto v : tr2) {
        s.insert(v);
    }

    s.erase(1);

    int ans = 0;
    for(auto v : s) {
        ll now = n;
        bool flg = false;
        while(now > 1) {
            // cout << now << endl;
            if(now % v == 0) {
                now = now / v;
            } else {
                flg = (now % v == 1);
                break;
            }
        }
        if(now == 1) flg = true;
        ans += flg;
    }

    cout << ans << endl;
    return 0;
}
// ===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

template <class T>
inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

vector<ll> enum_div(ll n) {
    vector<ll> ret;
    for(ll i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i != 1 && i * i != n) {
                ret.push_back(n / i);
            }
        }
    }
    ret.push_back(n);
    // n自身もくわえたければ

    // sort(ret.begin(), ret.end());
    // 最小順であることは保証されないので、必要に応じて。
    // この場合、O(sqrt(N)*(log(N)+1))
    return ret;
}