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# (Mono 4.6.2.0) (judge verdict: Runtime Error)

using System;
using System.Linq;
using System.Collections.Generic;

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC161.F();
        }

        class ABC161
        {
            public static void A()
            {
                var X = Read.Int();
                var Y = Read.Int();
                var Z = Read.Int();
                Console.WriteLine("{0} {1} {2}", Z, X, Y);
            }
            public static void B()
            {
                var N = Read.Int();
                var M = Read.Int();
                var A = Read.IntN();
                Array.Sort(A);
                var total = A.Sum();
                Console.WriteLine(A[N - M] * 4 * M < total ? "No" : "Yes");
            }
            public static void C()
            {
                var N = Read.Long();
                var K = Read.Long();
                var a = N % K;
                Console.WriteLine(Math.Min(a, K - a));
            }
            public static void D()
            {
                var K = Read.Int();
                var list = new List<long>();
                for(int keta = 1; keta <= 10; ++keta)
                {
                    for(int i = 1; i <= 9; ++i)
                    {
                        D_Loop(keta, i, 1, list);
                    }
                }
                Console.WriteLine(list[K - 1]);
            }
            static void D_Loop(int keta, long x, int current, List<long> list)
            {
                if (current == keta) { list.Add(x); return; }
                long last = x % 10;
                if(last > 0)
                {
                    D_Loop(keta, x * 10 + last - 1, current + 1, list);
                }
                D_Loop(keta, x * 10 + last, current + 1, list);
                if (last < 9)
                {
                    D_Loop(keta, x * 10 + last + 1, current + 1, list);
                }
            }
            public static void E()
            {
                var N = Read.Int();
                var K = Read.Int();
                var C = Read.Int();
                var S = Read.Str();
                var dp = new int[N + C + 2];
                for (int i = N; i > 0; --i)
                {
                    dp[i] = dp[i + 1];
                    if (S[i - 1] == 'o') { dp[i] = Math.Max(dp[i], dp[i + C + 1] + 1); }
                }
                if(dp[1] > K) { return; }
                int currentCount = 0;
                int minNext = 0;
                for(int i = 1; i <= N; ++i)
                {
                    if (S[i - 1] == 'o') { currentCount++; if (currentCount == 1) { minNext = i + C; } }
                    if (dp[i] > dp[i + 1])
                    {
                        if (currentCount == 1) { Console.WriteLine(i); i += C; } else { i = Math.Max(i, minNext); }
                        currentCount = 0;
                    }
                }
            }
            public static void F()
            {
                var N = Read.Long();
                if (N == 2) { throw new Exception(); }
                var divN1 = Util.Dividor(N - 1);
                var divN = Util.Dividor(N);
                long total = 0;
                foreach(var d in divN)
                {
                    var X = N;
                    while (X % d == 0) { X /= d; }
                    if (X % d == 1) {
                        total++;
                    }
                }
                Console.WriteLine(total + divN1.Count);
            }
        }



        class Util
        {
            public static List<long> Dividor(long N)
            {
                var list = new List<long>();
                if (N > 1) { list.Add(N); }                
                for (long i = 2; i <= 1000000; ++i)
                {
                    if (i * i > N) { break; }
                    if (N % i == 0)
                    {
                        list.Add(i);
                        var j = N / i;
                        if (i != j) { list.Add(j); }
                    }
                }
                return list;
            }


            public static long Power(long a, long n, long p)
            {
                long res = 1;
                long mult = a;
                for (int i = 0; i < 40; ++i)
                {
                    if ((n & ((long)1 << i)) > 0)
                    {
                        res = (res * mult) % p;
                    }
                    mult = (mult * mult) % p;
                }
                return res;
            }
            public static long Inverse(long a, long p)
            {
                long b = p, c = 1, d = 0, e = 0, f = 0;
                while (b != 0)
                {
                    e = a / b;
                    f = b; b = a - e * b; a = f;
                    f = d; d = c - e * d; c = f;
                }
                c %= p;
                return c + (c < 0 ? p : 0);
            }
        }
        struct MOD
        {
            public static long P = 1000000007;
            public readonly long V;

            public MOD(long a) { this.V = a; }
            public static implicit operator MOD(long a) { return new MOD(a); }
            public static MOD operator +(MOD a, MOD b) { return new MOD((a.V + b.V) % P); }
            public static MOD operator -(MOD a, MOD b) { return new MOD((a.V - b.V + P) % P); }
            public static MOD operator *(MOD a, MOD b) { return new MOD((a.V * b.V) % P); }
            public static MOD operator /(MOD a, MOD b) { return new MOD((a.V * b.Inverse().V) % P); }
            public MOD Inverse() { return Util.Inverse(V, P); }
            public MOD Power(long n) { return Util.Power(V, n, P); }
            public override string ToString() { return V.ToString(); }
        }


        static class Read
        {
            static Queue<string> queue = new Queue<string>();
            static void Enqueue() { var ss = Console.ReadLine().Split(' '); foreach (var s in ss) { queue.Enqueue(s); } }
            public static int Int() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt32(queue.Dequeue()); }
            public static long Long() { if (queue.Count == 0) { Enqueue(); } return Convert.ToInt64(queue.Dequeue()); }
            public static string Str() { if (queue.Count == 0) { Enqueue(); } return queue.Dequeue(); }
            public static int[] IntN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray(); }
            public static long[] LongN() { return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray(); }
            public static string[] StrN() { return Console.ReadLine().Split(' '); }
            public static Tuple<int, int>[] TupleInt(int n) { List<Tuple<int, int>> list = new List<Tuple<int, int>>(); for (int i = 0; i < n; ++i) { var ab = Read.IntN(); list.Add(new Tuple<int, int>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<long, long>[] TupleLong(int n) { List<Tuple<long, long>> list = new List<Tuple<long, long>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<long, long>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<string, string>[] TupleStr(int n) { List<Tuple<string, string>> list = new List<Tuple<string, string>>(); for (int i = 0; i < n; ++i) { var ab = Read.StrN(); list.Add(new Tuple<string, string>(ab[0], ab[1])); } return list.ToArray(); }
            public static Tuple<double, double>[] TupleDouble(int n) { List<Tuple<double, double>> list = new List<Tuple<double, double>>(); for (int i = 0; i < n; ++i) { var ab = Read.LongN(); list.Add(new Tuple<double, double>(ab[0], ab[1])); } return list.ToArray(); }
            public static long[,] LongMatrix(int r, int c)
            {
                var mat = new long[r, c];
                for (int i = 0; i < r; ++i)
                {
                    var x = Read.LongN();
                    for (int j = 0; j < c; ++j)
                    {
                        mat[i, j] = x[j];
                    }
                }
                return mat;
            }
            public static Dictionary<int, HashSet<int>> AdjacencyList(int N, int M)
            {
                Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new HashSet<int>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1]);
                    dict[ab[1]].Add(ab[0]);
                }
                return dict;
            }
            public static Dictionary<int, Dictionary<int, long>> AdjacencyListWithWeight(int N, int M)
            {
                Dictionary<int, Dictionary<int, long>> dict = new Dictionary<int, Dictionary<int, long>>();
                for (int i = 0; i <= N; ++i)
                {
                    dict.Add(i, new Dictionary<int, long>());
                }
                for (int i = 0; i < M; ++i)
                {
                    var ab = Read.IntN();
                    dict[ab[0]].Add(ab[1], ab[2]);
                    dict[ab[1]].Add(ab[0], ab[2]);
                }
                return dict;
            }
        }
    }
}