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: Runtime Error)

    #define ll long long
    #define pub push_back
    #define pob pop_back
    #define puf push_front
    #define pof pop_front
    #define mp make_pair
    #define fo(i , n) for(ll i = 0 ; i < n ; i++)
    //#include<bits/stdc++.h>
    #include<iomanip>
    #include<cmath>
    #include<cstdio>
    #include<utility>
    #include<iostream>
    #include<vector>
    #include<string>
    #include<algorithm>
    #include<map>
    #include<queue>
    #include<set>
    #include<stack>
    ll pi = acos(-1) ;
    ll z =  998244353 ;
    ll inf = 100000000000000000 ;
    ll p1 = 37 ;
    ll p2 = 53 ;
    ll mod1 =  202976689 ;
    ll mod2 =  203034253 ;
    ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
    ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
    ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
    ll max(ll a , ll b){if(a > b) return a ; return b ;}
    ll min(ll a , ll b){if(a < b) return a ; return b ;}
    ll left(ll i){return ((2*i)) ;}
    ll right(ll i){return ((2*i) + 1) ;}
    void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;}
    //ios_base::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);
    using namespace std ;
    #include <ext/pb_ds/assoc_container.hpp> 
    #include <ext/pb_ds/tree_policy.hpp> 
    using namespace __gnu_pbds; 
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    // ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
    // s.find_by_order(i)  itertor to ith element (0 indexed)

    void solve()
    {
        ll n ;
        cin >> n ;
        ll m = n-1 ;
        vector<ll> fact_1 , fact_2 ;
        for(ll i = 1 ; i*i <= n ; i++)
        {
            if(n % i == 0)
            {
                if(i != 1)
                    fact_1.pub(i) ;
                if(i*i != n)
                    fact_1.pub(n/i) ;
            }
        }
        for(ll i = 1 ; i*i <= m ; i++)
        {
            if(m % i == 0)
            {
                if(i != 1)
                    fact_2.pub(i) ;
                if(i*i != m && (m/i != 1))
                    fact_2.pub(m/i) ;
            }
        }
        ll ans = fact_2.size() ;
        fo(i , fact_1.size())
        {
            ll a = n ;
            ll f  = fact_1[i] ;
            while(a%f == 0)
                a /= f ;
            if((a-1)%f == 0)
                ans++ ;
        }
        cout << ans << endl ;
    }

    int main()
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
        #ifndef ONLINE_JUDGE
        freopen("inputf.txt" , "r" , stdin) ;
        freopen("outputf.txt" , "w" , stdout) ;
        freopen("error.txt" , "w" , stderr) ;
        #endif
        
        ll t ;
        //cin >> t ;
        t = 1 ;
        while(t--)
        {
            solve() ;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

        return 0;
    }