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):
n = int(input())


m = n - 1
i = 2
ans = 1
while i * i <= m:
    if m % i == 0:
        num = 1
        while m % i == 0:
            num += 1
            m //= i
        ans *= num
    i = i + 1
if m != 1:
    ans *= 2
ans -= 1



m = n
import numpy as np
i = 2
factor = []
while i * i <= n:
    if n % i == 0:
        l = []
        num = 1
        l.append(num)
        while n % i == 0:
            num *= i
            l.append(num)
            n //= i
        factor.append(np.array(l))
    i = i + 1
if n > 1:
    factor.append(np.array([1, n]))


divisor = factor[-1]
for i in range(len(factor) - 1):
    divisor = np.outer(divisor, factor[i])
divisor = np.outer(np.array(1), divisor)


for i in divisor[0]:
    if i == 1:
        continue
    n = m
    while n % i == 0:
        n //= i
    if n % i == 1:
        ans += 1

print(ans)

Solution (Python):
n = int(input())


m = n - 1
i = 2
ans = 1
while i * i <= m:
    if m % i == 0:
        num = 1
        while m % i == 0:
            num += 1
            m //= i
        ans *= num
    i = i + 1
if m != 1:
    ans *= 2
ans -= 1



m = n
import numpy as np
i = 2
factor = []
while i * i <= n:
    if n % i == 0:
        l = []
        num = 1
        l.append(num)
        while n % i == 0:
            num *= i
            l.append(num)
            n //= i
        factor.append(np.array(l))
    i = i + 1
if n > 1:
    factor.append(np.array([1, n]))


divisor = factor[-1]
for i in range(len(factor) - 1):
    divisor = np.outer(divisor, factor[i])
divisor = np.outer(np.array(1), divisor)


for i in divisor[0]:
    if i == 1:
        continue
    n = m
    while n % i == 0:
        n //= i
    if n % i == 1:
        ans += 1

print(ans)

Solution (Python):
n = int(input())


if n == 2:
    print(1)
    exit()
if n == 3:
    print(2)
    exit()


m = n - 1
i = 2
ans = 1
while i * i <= m:
    if m % i == 0:
        num = 1
        while m % i == 0:
            num += 1
            m //= i
        ans *= num
    i = i + 1
if m != 1:
    ans *= 2
ans -= 1



m = n
import numpy as np
i = 2
factor = []
while i * i <= n:
    if n % i == 0:
        l = []
        num = 1
        l.append(num)
        while n % i == 0:
            num *= i
            l.append(num)
            n //= i
        factor.append(np.array(l))
    i = i + 1
if n > 1:
    factor.append(np.array([1, n]))


divisor = factor[-1]
for i in range(len(factor) - 1):
    divisor = np.outer(divisor, factor[i])
divisor = np.outer(np.array(1), divisor)


for i in divisor[0]:
    if i == 1:
        continue
    n = m
    while n % i == 0:
        n //= i
    if n % i == 1:
        ans += 1

print(ans)

Solution (Python):
n = int(input())
from numpy import sqrt
cnt = 2
rt = int(sqrt(n))
for i in range(2,rt+1):
    if n % i == 0:
        m = n
        while m%i ==0:
            m = m//i
        if m%i == 1:
            cnt += 1
    elif (n-1) % i ==0:
        cnt += 2
if n == rt ** 2 + 1:
    cnt -= 1
print(cnt)

Solution (Python):
N=int(input())
D={}
for i in range(2,int(N**0.5)+1):
    n=N
    
    while n%i==0 and n!=i:
        n//=i
    
    if n==i or n%i==1:
        D[i]=1
        

N1=N-1
for i in range(1,int(N1**0.5)+1):
    if N1%i==0:
        D[i]=1
        D[N1//i]=1

print(len(D))

Solution (Python):
n=int(input())

def m_div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

def check(num,k):
    if k==1:
        return False

    while num>=k:
        if num%k==0:
            num=num//k
        else:
            break
    num%=k
    return num==1

n1divs = m_div(n-1)
ndivs  = m_div(n)

ans=[]
for num in n1divs:
    if check(n,num):
        ans.append(num)
for num in ndivs:
    if check(n,num):
        ans.append(num)
print(len(set(ans)))

Solution (Python):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if ((n % i == 0)):
            if(i>1):
                divisors.append(i)
            if i != n // i:
                if(n//i>1):
                    divisors.append(n//i)
    return divisors

def test(n,ans_list):
    ans_list.append(n)
    ans_list = ans_list + make_divisors(n-1)
    
    for ans in make_divisors(n):
        nn = n
        while(nn%ans == 0):
            nn = nn/ans
        nn = nn%ans
        if(nn == 1):
            ans_list.append(ans)
    return ans_list

n = int(input())

ans_list = []

answer = list(set(test(n,ans_list)))


print(len(answer))

Solution (Python):
def calc_factors(N):
    """
    約数をlistでreturn
    この問題はK>1なので、約数に1を含めてない
    """
    i=2
    factors={N}
    while i*i<=N:
        if N%i==0:
            factors.add(i)
            factors.add(N//i)
        i+=1
    return list(sorted(factors))


N = int(input())


if N==2:
    print(1)
    exit()

ans = len(calc_factors(N-1))

for fac in calc_factors(N):
    tmp=N
    while tmp%fac==0:
        tmp//=fac
    if tmp%fac==1:
        ans+=1
print(ans)

Solution (Python):
def main():
    n = int(input())
    count = 2
    sqrt = int(n ** (1/2))
    for i in range(2,sqrt + 1):
        if n % i == 1:
            count += 2
        elif n % i == 0:
            ins = n
            while ins % i == 0:
                ins = ins // i
            if ins % i == 1:
                count += 1
    if sqrt ** 2 == n - 1:
        count -= 1

    print(count)


if __name__ == "__main__":
    main()

Solution (Python):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    return divisors


n = int(input())
ans = len(make_divisors(n - 1))
divisors = []
for i in make_divisors(n):
    j = n
    if i != 1:
        while j % i == 0:
            j //= i
        if (j - 1) % i == 0:
            divisors.append(i)
print(ans + len(divisors) - 1)

Solution (Python):
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors
def resolve():
    N = ir()
    ans = len(make_divisors(N-1))-1
    d = make_divisors(N)
    d.remove(1)
    for i in d:
        tmp = N
        while tmp != 1 and tmp >= i:
            if tmp%i > 0:
                tmp %= i
            else:
                tmp //= i
        if tmp == 1:
            ans += 1
    print(ans)
resolve()

Solution (Python):

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

N = int(input())
divs = make_divisors(N)

divs2 = make_divisors(N-1)
ans = len(sorted(divs2))-1
for div in divs[1:]:
    tmp = N
    while tmp%div == 0:
        tmp //= div
    if tmp%div == 1:
        ans += 1
print(ans)

Solution (Python):
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)


def input(): return sys.stdin.readline().rstrip()


N = int(input())


def f(x):
    ans = set()
    i = 1
    while i * i <= x:
        if x % i == 0:
            ans.add(i)
        i += 1
    for i in ans.copy():
        ans.add(x // i)
    return ans

ans = set()
for K in f(N) | f(N - 1):
    if K == 1:
        continue
    n = N
    while n % K == 0:
        n //= K
    if n % K == 1:
        ans.add(K)

print(len(ans))

Solution (Python):
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)


def input(): return sys.stdin.readline().rstrip()


N = int(input())


def f(x):
    ans = set()
    i = 1
    while i * i <= x:
        if x % i == 0:
            ans.add(i)
        i += 1
    for i in ans.copy():
        ans.add(x // i)
    return ans

ans = set()
for K in f(N) | f(N - 1):
    if K == 1:
        continue
    n = N
    while n % K == 0:
        n //= K
    if n % K == 1:
        ans.add(K)

print(len(ans))

Solution (Python):
N = int(input())

def divider(n):
  dividers = []
  for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
      dividers.append(i)
      if i != n // i:
        dividers.append(n // i)
  dividers.sort()
  dividers.remove(1)
  return dividers


cnt = len(divider(N - 1))
for k in divider(N):
  n = N
  while n % k == 0:
    n /= k
  if n % k == 1:
    cnt += 1
print(cnt)

Solution (Python):
n = int(input())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    
    return divisors



ansl = make_divisors(n-1)
ansl.remove(1)
for i in make_divisors(n):
    if i == 1:
        continue
    k = n
    while k:
        if k % i == 0:
            k //= i
        else:
            if k % i == 1:
                ansl.append(i)
            break

print(len(set(ansl)))

Solution (Python):
def main():
    N = int(input())

    

    def divisor_set(x):
        ret = set()
        if x > 1:
            ret.add(x)

        d = 2
        while d * d <= x:
            if x % d == 0:
                ret.add(d)
                ret.add(x // d)
            d += 1
        return ret

    
    
    

    ans = 0
    ans += len(divisor_set(N - 1))

    
    
    

    for k in divisor_set(N):
        x = N
        while x % k == 0:
            x //= k
        if x % k == 1:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from math import ceil

def enum_divisor(n):
    res = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i != 0:
            continue
        res.append(i)
        if i * i != n:
            res.append(n // i)
    return res

ans = 0
n = int(input())
for x in enum_divisor(n):
    if x == 1:
        continue
    tmp = n
    while tmp % x == 0:
        tmp //= x
    if tmp % x == 1:
        ans += 1

ans += len(enum_divisor(n - 1)) - 1
print(ans)

Solution (Python):
def resolve():
    n = int(input())
    def divisor(n):
        ass = []
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                ass.append(i)
                if i ** 2 == n:
                    continue
                ass.append(n // i)
        return ass  
    g = sorted(divisor(n))

    q = []
    for i in range(1, len(g)):
        m=n
        while m >= g[i]:
            if m %g[i] == 0:
                m = m//g[i]
            else:
                m = m%g[i]
        if m == 1:
            q.append(g[i])
    print(len(set(divisor(n-1)+q))-1)

resolve()

Solution (Python):
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

a = make_divisors(n)
b = make_divisors(n-1)

ans = (len(b) - 1)
for i in a:
    x = n
    if i == 1:
        continue
    elif i == n:
        ans += 1
    else:
        while x % i == 0:
            x /= i
        if x % i == 1:
            ans += 1

print(ans)

Solution (Python):
def divisors(n):
    ret = set()
    for i in range(1, int(n**0.5)+2):
        if n % i == 0:
            ret.add(i)
            ret.add(n // i)
    ret.remove(1)
    return ret


def main():
    N = int(input())
    s = divisors(N)
    ans = divisors(N-1)

    for x in s:
        n = N
        if x == 1:
            continue
        while(n % x == 0):
            n = n // x
        if n % x == 1:
            ans.add(x)
    print(len(ans))


main()

Solution (Python):
def main():
    def trial_division(n):
        divs = set()
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divs.add(i)
                if i != n//i:
                    divs.add(n//i)
        return divs

    def gcd(x, y):
        if y == 0:
            return x
        while y != 0:
            x, y = y, x % y
        return x

    N = int(input())
    ans = 0
    divs = trial_division(N) | trial_division(N-1)
    for d in divs:
        if d == 1:
            continue
        num = N
        while num % d == 0 and d <= num:
            num //= d
        if num % d == 1:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

def divisor(N):
    ret = []
    for i in range(1, int(N**0.5)+1):
        if N % i == 0:
            ret.append(i)
            if N // i != i:
                ret.append(N//i)
    return ret


div_N = divisor(N)
div_N_1 = divisor(N-1)

ans = 0

for k in div_N[1:]:
    n = N
    while n % k == 0:
        n //= k
    if n % k == 1:
        ans += 1

ans += len(div_N_1) - 1

print(ans)

Solution (Python):
N=int(input())
if N==2:
  print(1)
  exit()
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)

    
  return divisors


d=make_divisors(N-1)
if not 2 in d:
  d.append(2)

d2=make_divisors(N)

for i in d2:
  if i!=N and i!=1 and i not in d:
    now=N
    while now%i==0:
      now/=i
    if now%i==1:
      d.append(i)
print(len(d))

Solution (Python):
from collections import Counter
from itertools import product


from functools import reduce
import operator
nproduct = lambda it: reduce(operator.mul,it,1)


def prime_factors(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            yield i
    if n > 1:
        yield n

def all_divisors(n):
    factors,counts = map(tuple,zip(*Counter(prime_factors(n)).items()))

    for p in product(*(range(c+1) for c in counts)):
        yield nproduct(v**k for v,k in zip(factors,p))

def num_divisors(n):
    return nproduct(c+1 for c in Counter(prime_factors(n)).values())


N = int(input())

cnt = num_divisors(N-1)
for d in all_divisors(N):
    if d == 1:
        continue
    x = N
    while x % d == 0:
        x //= d
    if x % d == 1:
        cnt += 1

print(cnt-1)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
for i in range(2,int(n**.5) + 1):
  if n % i == 0:
    tmp = n
    while tmp % i==0:
      tmp //= i
    if (tmp-1) % i == 0:ans += 1

    if n//i != i:
      tmp = n;i = n//i
      while tmp % i==0:
        tmp //= i
      if (tmp-1) % i == 0:ans += 1

for i in range(2,int((n-1)**.5 )+ 1):
  if (n-1) % i == 0:
    if (n-1) // i == i: ans += 1
    else: ans += 2

print(ans+1 + int(n != 2))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from copy import deepcopy


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors


n = int(readline())
ans = len(make_divisors(n - 1))
for check in make_divisors(n):
    if check == 1:
        continue
    nn = deepcopy(n)
    while nn % check == 0:
        nn //= check
    if nn % check == 1:
        ans += 1
print(ans - 1)

Solution (Python):
N = int(input())
count = 0
if N ==2:
    print(1)
else:

    for i in range(2,int((N-1)**0.5)+1):
        if (N-1)%i == 0:
            count += 1
            if (N-1)//i != i:
                count += 1

    for j in range(2,int(N**0.5)+1):
        if N%j == 0:
            n = N
            while n%j == 0:
                n = n//j
            if n%j == 1:
                count += 1
            if N//j != j:
                n = N
                while n%(N//j) == 0:
                    n = n//(N//j)
                if n%(N//j) == 1:
                    count += 1
    print(count+2)

Solution (Python):
def divisors(x):
    div=[]
    for i in range(1,x+1):
        if i*i>x:
            break
        if x%i==0:
            div.append(i)
            if x%i!=i:
                div.append(x//i)
    return div

n=int(input())
ans=set([])
for k in divisors(n):
    if k==1:continue
    N=n
    while  N%k==0:
        N//=k
    N%=k
    if N==1:
        ans.add(k)

for j in divisors(n-1):
    if j==1:continue
    ans.add(j)
print(len(ans))

Solution (Python):
import sys
from collections import deque
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def divisor(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

N = I()

l = divisor(N)
l = list(set(l))

cnt = 0
for x in l:
  if x == 1:
    continue
  num = N
  while num%x == 0:
    num //= x
  if num%x == 1:
    cnt += 1

l = []

k = divisor(N-1)
cnt += len(k) - 1
print(cnt)

Solution (Python):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors
n=int(input())
a=make_divisors(n)[1:]
ans=0
for i in a:
    k=n
    while k%i==0:
        k//=i
    if k%i==1:
        ans+=1
ans+=len(make_divisors(n-1))-1
print(ans)

Solution (Python):
import sys
def solve():
    input = sys.stdin.readline
    N = int(input())
    if N == 2: print(1)
    else:
        K = {N, N-1}
        for i in range(2, N + 1):
            if i ** 2 > N: break
            if N % i == 0:
                k = N
                while k % i == 0:
                    k //= i
                if k % i == 1: K |= {i}
            
            if (N - 1) % i == 0:
                K |= {i}
                if i ** 2 != N - 1: K |= {(N - 1) // i}
        print(len(K))
        
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
from copy import copy

def make_divisors(n):
    """約数を全列挙する
    """
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors


N0 = int(input())
cand = set(make_divisors(N0) + make_divisors(N0-1))

ans = 0
for K in cand:
    if K == 1:
        continue
    N = copy(N0)
    while N%K == 0:
        N //= K
    N %= K
    if N == 1:
        ans += 1

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors
a = make_divisors(N)
b = make_divisors(N - 1)
s = set(a + b)
res = 0
for x in s:
  if x == 1: continue
  t = N + 0
  while t % x == 0: t //= x
  res += (t % x == 1)
print(res)

Solution (Python):
N = int(input())

def isOk(k):
    n = N
    while n % k == 0:
        n //= k
    return n % k == 1


def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    
    return divisors

div1 = divisors(N)
div2 = divisors(N - 1)

ans = len([0 for d in div1 if d != 1 and isOk(d)]) + len([0 for d in div2 if d != 1 and isOk(d)])
print(ans)

Solution (Python):
import math


def list_divisor(n):
    divisor1 = {1}
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            divisor1.add(i)

    divisor2 = {n}
    for i in divisor1:
        divisor2.add(n // i)

    return divisor1 | divisor2


def main():
    n = int(input().rstrip())

    sub_only = len(list_divisor(n - 1)) - 1

    div_included = 0
    for d in (list_divisor(n) - {1}):
        n1 = n // d
        while n1 % d == 0:
            n1 = n1 // d

        if n1 == 1:
            div_included += 1
            continue

        if d in list_divisor(n1 - 1):
            div_included += 1

    print(sub_only + div_included)


if __name__ == '__main__':
    main()

Solution (Python):
import math

N = int(input())

def enumerate_divisors(N):
  all_divisors = set()
  for divisor in range(1, int(math.sqrt(N)) + 1):
    if N%divisor == 0:
      if divisor == 1:
        all_divisors.add(N/divisor)
      else:
        all_divisors = all_divisors | {divisor, N/divisor}

  all_divisors = list(all_divisors)
  return all_divisors

def calculate_reminder(N, d):
  while True:
    reminder = N%d
    if reminder == 0:
      N /= d
    else:
      return reminder

if N == 2:
  counter = 1
else:
  counter = len(enumerate_divisors(N-1))
  for div in enumerate_divisors(N):
    if calculate_reminder(N, div) == 1:
      counter += 1

print(counter)

Solution (Python):
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

d1 = make_divisors(n)
d2 = make_divisors(n-1)

ans = 0
for k in d1:
    if k == 1:
        continue
    temp = n
    while temp%k == 0:
        temp //= k
    if temp%k == 1:
        ans += 1
ans += len(d2)-1
print(ans)

Solution (Python):
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

d1 = make_divisors(n)
d2 = make_divisors(n-1)

ans = 0
for k in d1:
    if k == 1:
        continue
    temp = n
    while temp%k == 0:
        temp //= k
    if temp%k == 1:
        ans += 1
ans += len(d2)-1
print(ans)

Solution (Python):
from math import sqrt
def div(n):
    s = set()
    for i in range(1, int(sqrt(n))+2):
        if n%i == 0:
            s.add(i)
            s.add(n//i)
    return s

def solve(x, n):
    while n % x == 0:
        n //= x
    if n % x == 1:
        return True
    return False

def main():
    n = int(input())
    t = div(n) | div(n-1)
    ans = 0
    for v in t:
        if v != 1 and solve(v, n):
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):

n_ori =int(input())
n_dif = n_ori - 1
sq_ori = int(n_ori**.5)
sq_dif = int(n_dif**.5)
divisor_ori = []
divisor_dif = []

for i in range(1, sq_ori+1):
	if n_ori % i == 0:
		divisor_ori.append(i)
		if i != n_ori // i:
			divisor_ori.append(n_ori//i)

for i in range(1, sq_dif+1):
	if n_dif % i == 0:
		divisor_dif.append(i)
		if i != n_dif // i:
			divisor_dif.append(n_dif//i)
			
cnt = 0
for k in divisor_ori:
	if k == 1:
		continue
	else:
		tmp = n_ori
		while tmp % k == 0:
			tmp = tmp//k

		if tmp % k == 1:
			cnt += 1

print(cnt + len(divisor_dif) - 1)

Solution (Python):
def divisors(n):
    lst = []; i = 1
    while i * i <= n:
        q, r = divmod(n, i)
        if r == 0:
            lst.append(i)
            if i != q: lst.append(q)
        i += 1
    return lst

N = int(input())
ans = len(divisors(N-1)) - 1
divs = divisors(N)
for k in divs:
    if k == 1: continue
    temp = N
    while temp % k == 0: temp //= k
    if temp % k == 1: ans += 1
print(ans)

Solution (Python):
import math
n = int(input())


divisors = []
for i in range(1, int(math.sqrt(n)) + 1):
    if n % i == 0:
        divisors.append(i)
        if i ** 2 != n:
            divisors.append(n // i)
divisors.sort()

candidates = set()
for k in divisors[1:]:
    tmp = n
    while True:
        if tmp % k != 0:
            break
        tmp = tmp // k
    if (tmp - 1) % k == 0:
        candidates.add(k)


divisors = []
for i in range(1, int(math.sqrt(n-1)) + 1):
    if (n-1) % i == 0:
        divisors.append(i)
        if i ** 2 != n-1:
            divisors.append((n-1) // i)

for k in divisors[1:]:
    candidates.add(k)

print(len(candidates))

Solution (Python):
from sys import stdin
import math

data = stdin.readline().rstrip().split()
N = int(data[0])

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

div_list = sorted(make_divisors(N))
count = 0

for i in div_list:
    if i == 1:
        continue
    tmp_N = N
    while(1):
        if tmp_N % i == 0:
            tmp_N = tmp_N // i
        else:
            r = tmp_N % i
            if r == 1:
                count += 1
            break
            

div_list_2 = sorted(make_divisors(N-1)) 
        
print(count + len(div_list_2) - 1)

Solution (Python):
import math

n = int (input())
sqr = int (math.sqrt(n))
ans = 1 

def check (x) :
    tmp = n
    while (tmp % x == 0) :
        tmp /= x
    return True if tmp % x == 1 else False

for i in range (2, sqr + 1) :
    if (n % i == 0) :
        if (check (i)) :
            ans += 1
        if (i != n / i and check (n / i)) :
            ans += 1
    
m = n - 1
if (m > sqr) :
    ans += 1 
    for i in range (2, sqr + 1) :
        if (m % i == 0) :
            ans += 1 
            if (i != m / i) :
                ans += 1

print (ans)

Solution (Python):
import sys
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

n = ni()
ans = len(make_divisors(n-1))-1
ls = make_divisors(n)[1:]

for i in ls:
    nn = n
    while nn%i == 0:
        nn = nn//i
    if nn%i == 1:
        ans += 1

print(ans)

Solution (Python):
N = int(input())

if N == 2:
    
    print(1)
    exit()

result = 2 
for K in range(2, int(N ** 0.5 + 1)):
    t = N
    while t >= K and t % K == 0:
        t //= K
    if t % K == 1:
        result += 1

    if (N-1) % K == 0 and (N-1) // K > K:
        result += 1
print(result)

Solution (Python):

def make_divisors(n: int, sort=False):
    
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    if sort:
        divisors.sort()
    return divisors


N = int(input())










ans = len(make_divisors(N - 1)) - 1  


candi = make_divisors(N)[1:]  
for k in candi:
    n = N
    while n % k == 0:
        n //= k
    if n % k == 1:
        ans += 1
print(ans)

Solution (Python):
def decomposition(x):
    ret = []
    for i in range(1, int(x**0.5)+1):
        if x%i==0:
            ret.append(i)
            if x//i!=i:
                ret.append(x//i)
    return sorted(ret)

n = int(input())
s = decomposition(n)
t = decomposition(n-1)
ans = 0
for num in s:
    if num==1:
        continue
    tmp = n
    while tmp%num==0:
        tmp = tmp//num
    if tmp%num==1:
        ans += 1
print(ans+len(t)-1)

Solution (Python):
N=int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return(divisors)

l1=make_divisors(N)
ans=len(make_divisors(N-1))-1

for i in l1:
    m=N
    while m%i==0 and m!=1 and m!=0 and i!=1:
        m//=i
    if m%i==1:
        ans+=1

print(ans)

Solution (Python):
N = int(input())
sqrt_N = int(N ** 0.5)

dividers_for_N = []
ans_list = []

for i in range(1, sqrt_N + 1):
    if (N - 1) % i == 0:
        ans_list.append(i)
        if i != (N - 1) // i:
            ans_list.append((N - 1) // i)

    if N % i == 0:
        dividers_for_N.append(i)
        if i != N // i:
            dividers_for_N.append(N // i)

dividers_for_N.remove(1)
ans_list.remove(1)
        
for i in dividers_for_N:
    num = N
    while num % i == 0:
        num //= i
    if num % i == 1:
        ans_list.append(i)

ans = len(ans_list)

print(ans)

Solution (Python):
N = int(input())
sqrt_N = int(N ** 0.5)

dividers_for_N = set()
ans_set = set()

for i in range(1, sqrt_N + 1):
    if (N - 1) % i == 0:
        ans_set.add(i)
        ans_set.add((N - 1) // i)

    if N % i == 0:
        dividers_for_N.add(i)
        dividers_for_N.add(N // i)

dividers_for_N -= {1}
ans_set -= {1}

for i in dividers_for_N:
    num = N
    while num % i == 0:
        num //= i
    if num % i == 1:
        ans_set.add(i)

ans = len(ans_set)

print(ans)

Solution (Python):
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))
def prime_decomposition(n):
    i = 2
    table = []
    while i*i <= n:
        while n%i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table
def prime_decomposition2(n):
    i = 2
    table = defaultdict(int)
    while i*i <= n:
        while n%i == 0:
            n //= i
            table[i] += 1
        i += 1
    if n > 1:
        table[n] += 1
    return table
def make_divisor(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    return divisors

N = int(input())
list_pd1 = make_divisor(N)
list_pd1.sort()
dict_pd2 = prime_decomposition2(N-1)



cnt = 1


for val in dict_pd2.values():
    cnt *= (val+1)
cnt -= 1


for k in list_pd1[1:]:
    
    sN = N
    while sN >= k:
        if sN%k==0:
            sN //= k
        else:
            sN %= k
    if sN == 1:
        cnt += 1

print(cnt)

Solution (Python):
nn = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    
    return divisors

ans = len(make_divisors(nn-1)) - 1
lis = make_divisors(nn)
del lis[0]

for i in lis:
  t = nn
  while t%i==0 and t != 0:
    t = t//i
  if t%i == 1:
    ans += 1

print(ans)