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: Wrong Answer)

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e18+9
#define N 100010
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

ll result(ll a, ll b, ll p){
    ll ans=1;
    if(b==(-1))
        b=p-2;
    while(b){
        if(b&1){
            ans=(ans*a)%p;
        }
        a=(a*a)%p;
        b>>=1;
    }
    return ans;
}

ll T,n,m;

int main(){
	if(fopen("input.txt", "r"))
	freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n;
    cin >> n;
    ll ans = 0;
    if(n<=100000000){
    for(ll i=2;i*i<=n;i++){
    	// if(n%i)
    	// 	continue;
    	if((n-1)%i==0){
    		ans++;
    	}
    	

    	ll d = n;
    	ll p = i;
    	while(1){
    		if(d%p==0)
    			d/=p;
    		else
    			break;
    	}
    	if(d==1){
    		ans++;
    		continue;
    	}
    	d = n;
    	p = i;
    	while(d>1){
    		if(d%p==0)
    			d/=p;
    		else
    			d-=p;
    	}
    	if(d==1){
    		ans++;
    		continue;
    	}

    }
    cout << ans+2;
}

	else{

		for(ll i=2;i*i*i<=n;i++){
    	// if(n%i)
    	// 	continue;
    	if((n-1)%i==0){
    		ans++;
    	}
    	

    	ll d = n;
    	ll p = i;
    	while(1){
    		if(d%p==0)
    			d/=p;
    		else
    			break;
    	}
    	if(d==1){
    		ans++;
    		continue;
    	}
    	d = n;
    	p = i;
    	while(d>1){
    		if(d%p==0)
    			d/=p;
    		else
    			d-=p;
    	}
    	if(d==1){
    		ans++;
    		continue;
    	}

    }
    if(sqrt(n)*sqrt(n)==n)
    	ans++;
    cout << ans+2;

	}

    return 0;
}