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 (Python):
import sys
input = sys.stdin.readline
from math import sqrt

x=int(input())

DIV=[]

for i in range(1,int(sqrt(x))+2):
    if x%i==0:
        DIV.append(i)
        DIV.append(x//i)

ANS=[]
for d in DIV:
    if d==1:
        continue
    k=x
    while k%d==0:
        k//=d
    if k%d==1:
        ANS.append(d)

t=x-1
for i in range(1,int(sqrt(t))+2):
    if t%i==0:
        ANS.append(i)
        ANS.append(t//i)

print(len(set(ANS))-1)

Solution (Python):
import sys
input = sys.stdin.readline
from math import sqrt

x=int(input())

DIV=[]

for i in range(1,int(sqrt(x))+2):
    if x%i==0:
        DIV.append(i)
        DIV.append(x//i)

ANS=[]
for d in DIV:
    if d==1:
        continue
    k=x
    while k%d==0:
        k//=d
    if k%d==1:
        ANS.append(d)

t=x-1
for i in range(1,int(sqrt(t))+2):
    if t%i==0:
        ANS.append(i)
        ANS.append(t//i)

print(len(set(ANS))-1)

Solution (Python):
n = int(input())
count = 1
for i in range(int(n ** 0.5)):
    test = i + 1
    n2 = n
    if test == 1:
        continue
    while n2 % test == 0:
        n2 //= test
    else:
        n2 %= test
    if n2 == 1:
        count += 1
n3 = n - 1
a = []
for i in range(1, int(n3 ** 0.5) + 1):
    if n3 % i == 0:
        temp = n3 // i
        if temp > int(n ** 0.5):
            a.append(temp)
count += len(a)
print(count)

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  





def check(d, n):
    if d == 1: return False
    while n % d == 0:
        n //= d
    return n % d == 1

n = ni()
ans = 0
for d in range(1, n+1):
    if d*d > n: break
    if n % d == 0:
        if check(d, n):
            ans += 1
        if d * d < n and check(n//d, n):
            ans += 1

for d in range(1, n):
    if d*d > n-1: break
    if (n-1) % d == 0:
        if d != 1:
            ans += 1
        if d * d < n-1 and n//d != 1:
            ans += 1
print(ans)

Solution (Python):

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(read())


def divisor(N):
    x = np.arange(1, 10 ** 6 + 1, dtype=np.int64)
    div = set(x[N % x == 0])
    return div | set(N // x for x in div)


cand = divisor(N) | divisor(N - 1)


def test(N, K):
    if K == 1:
        return False
    while N % K == 0:
        N //= K
    return N % K == 1


answer = sum(test(N, d) for d in cand)
print(answer)

Solution (Python):
def divisor(n):
    res = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            res.append(i)
            if i**2 == n:
                continue
            res.append(n//i)
    return res
n = int(input())
res = divisor(n)
ans = len(divisor(n-1))-1
for r in res:
    if r == 1:
        continue
    tmp = n
    while tmp%r==0:
        tmp//=r
    if tmp%r == 1:
        ans+=1
print(ans)

Solution (Python):

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(read())


def divisor(N):
    x = np.arange(1, 10 ** 6 + 1, dtype=np.int64)
    div = set(x[N % x == 0])
    return div | set(N // x for x in div)


cand = divisor(N) | divisor(N - 1)


def test(N, K):
    if K == 1:
        return False
    while N % K == 0:
        N //= K
    return N % K == 1


answer = sum(test(N, d) for d in cand)
print(answer)