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>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
int x, y, a, b, c;
V<P<int, int>> v;
struct prime{
  static const int N = 1e6;
  vector<ll> pr;
  int z[N+1];
  prime(){
    for (int i=2; i<=N; ++i) {
      if(!z[i]) z[i] = i, pr.push_back(i);
      for (int j=0; j<(int)pr.size() && pr[j]<=z[i] && i*pr[j]<=N; ++j) z[i*pr[j]] = pr[j];
    }
  }
  vector<pair<ll, int>> division(ll a){
    vector<pair<ll, int>> v;
    for(ll b:pr){
      if(a<=N) goto fast;
      if(b*b > a) break;
      if(a%b) continue;
      v.emplace_back(b, 0);
      while(a%b==0) a/=b, v.back().second++;
    }
    if(a>1) v.emplace_back(a, 1);
    return v;
fast:
    int p = -1;
    while(a>1){
      if(z[a] != p) v.emplace_back(z[a], 0);
      p = z[a];
      a /= z[a];
      v.back().second++;
    }
    return v;
  }
  vector<ll> divisor(ll m){
    vector<ll> v{1};
    for(auto &a:division(m)){
      int s=v.size();
      ll b=1;
      for(int i=0; i<a.second; i++){
        b *= a.first;
        for(int j=0; j<s; j++) v.push_back(v[j]*b);
      }
    }
    sort(v.begin(), v.end());
    return v;
  }
} pr;
ll n;
bool simulate(ll n, ll k){
  if(k==1) return false;
  while(n%k == 0) n /= k;
  return n%k == 1;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int ans = 0;
  for(ll a:pr.divisor(n  )) ans += simulate(n, a);
  for(ll a:pr.divisor(n-1)) ans += simulate(n, a);
  cout << ans << endl;
}