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

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

typedef long long int ll;
typedef vector<ll> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int mxn = 1e5;
// int cnt1[mxn+2],cnt2[mxn+2];

void solve(){
	ll n,cpyn;
	cin >> n;
	cpyn=  n;
	vi divn;
	divn.pb(n);
	vi divn1;
	divn1.pb(n-1);

	for(ll i =2;i*i<=n;i++){
		if(n%i==0){
			divn.pb(i);
			if(i*i!=n)
				divn.pb(n/i);
		}
	}
	n--;
	for(ll i =2;i*i<=n;i++){
		if(n%i==0){
			divn1.pb(i);
			if(i*i!=n)
				divn1.pb(n/i);
		}
	}

	ll ans = 0;
	ans+=divn1.size();
	n = cpyn;
	for(auto e:divn){
		n = cpyn;
		while(n%e==0){
			n/=e;
		}
		if(n%e==1){
			// cout << e << endl;
			ans++;
		}
	}
	if(cpyn==2)
		ans--;
	cout << ans << endl;
}

int main(){
	fast;
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("output.txt","w",stdout);
	// #endif

	// int t;cin >> t;while(t--)
		solve();
}