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>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	ll n;
	cin >> n;
	int ans = 0;
	for(ll i = 1; i * i <= n-1; i++){
		if((n-1) % i != 0) continue;
		if(i != 1)ans++;
		ll j = (n-1)/i;
		if(i != j) ans++;
	}
	// cerr << ans << endl;
	for(ll i = 1; i * i <= n; i++){
		if(n % i != 0) continue;
		ll j = n/i;
		ll t = n;
		while(t % j == 0 && t > 1){
			t /= j;
		}
		if(t % j == 1) ans++;
		if(i == 1 || i == j) continue;
		t = n;
		while(t % i == 0 && t > 1){
			t /= i;
		}
		if(t % i == 1) ans++;
	}
	cout << ans << endl;
	return 0;
}