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)


/*
  AUTHOR:SOURABH
  CREATED:03:04:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

ll sum;

void solve(ll x,ll y)
{
    ll p=y,r;
    W(p%x==0)
    p/=x;
    r=p%x;
    if(r==1)
        sum++;
    
    if(x==y)
        return;
        
    p=x;
    W(p%y==0)
    p/=y;
    r=p%y;
    if(r==1)
        sum++;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll t,i,k,v,x,y;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>k;
        v=k;
        k--;
        for(i=1;i*i<=k;i++)
        {
            if(k%i==0)
            {
                if(i!=k/i)
                    sum+=2;
                else
                    sum+=1;
            }
        }
        k=v;
        for(i=2;i*i<=k;i++)
        {
            if(k%i==0)
            {
                x=i,y=k/i;
                solve(x,y);
            }
        }
        cout<<sum;
    }
    return 0;
}