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: Runtime Error)

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
mt19937 rnd(1337);
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define pNN pair <Node *, Node *>
#define SZ(x) (int)(x).size()
#define pii pair <int, int>
#define pb push_back
#define rev reverse
#define ins insert
#define ers erase
#define S second
#define F first
#define int ll
const int N = 2e5 + 10, INF = 1e9 + 10;


vector <int> g[N];

int h[N], d[N];
bool used[N];
int sum[N];
int n, k, c;
int cnt = 0;

void dfs(int v) {
	used[v] = true;
	for (auto to : g[v]) {
		if (!used[to]) {
			h[to] = h[v] + 1;
			dfs(to);
			d[v] = max(d[v], d[to]);
			sum[v] += sum[to];
		}
	}
	++h[v];
	++d[v];
	if (h[v] >= k) {
		++cnt;
		++sum[v];
	}
}

void solve() {
	cin >> n >> k >> c;
	string s;
	cin >> s;
	vector <int> vec;
	for (int i = 0; i < n; ++i) {
		if (s[i] == 'o') {
			vec.pb(i + 1);
		}
	}
	int ptr = -1;
	for (int i = 0; i < SZ(vec); ++i) {
		while (vec[ptr + 1] <= vec[i] - c - 1) {
			++ptr;
		}
		if (ptr != -1) {
			g[ptr].pb(i);
		}
	}
	for (int i = 0; i < SZ(vec); ++i) {
		if (!used[i]) {
			dfs(i);
		}
	}

	for (int i = 0; i < SZ(vec); ++i) {
		if (sum[i] < cnt) {
			continue;
		}
		if (i != 0) {
			if (h[i - 1] + d[i] - 1 >= k) {
				continue;
			}
		}
		cout << vec[i] << '\n';
	}
	
}
 
signed main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    #ifdef Solenoid555
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1;
    //cin >> t;
    while(t--) solve();
    return 0;
}