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):
from sys import stdin
def make_divisors(n):
    mod0 = set()
    mod1 = set()
    for i in range(2, int(n**0.5)+1):
        if n%i==0:
            mod0.add(i)
            mod0.add(n/i)
        if (n-1)%i==0:
            mod1.add(i)
            mod1.add((n-1)/i)
    return mod0,mod1

N=list(map(int,(stdin.readline().strip().split())))

num=N[0]
if num==2:print(1)
else:
    K=0
    mod0,mod1=(make_divisors(num))
    
    
    for i in mod0:
        num = N[0]
        while(num % i == 0):
            num/=i

        if num%i==1:
            K+=1
    K+=len(mod1)+2
    print(K)

Solution (Python):

import sys
sys.setrecursionlimit(10**8)
INF = float("inf")

from collections import Counter


def factorial(n):
    prime_count = Counter()

    for i in range(2, int(n**0.5) + 2):
        while n % i == 0:
            n /= i
            prime_count[i] += 1
    if n > 1:
        prime_count[int(n)] += 1

    return prime_count


def num_divisors(prime_count):
    num = 1

    for prime, count in prime_count.items():
        num *= (count + 1)

    return num


def divisors(n):
    ret = set()
    for i in range(1, int(n ** 0.5) + 1):
        d, m = divmod(n, i)
        if m == 0:
            ret.add(i)
            ret.add(d)
    return sorted(ret)


def solve(N: int):

    f = factorial(N-1)
    ans = num_divisors(f)-1

    divs = divisors(N)
    for k in divs:
        if k == 1:
            continue
        n = N
        while n % k == 0:
            n = n//k
            if n == 1:
                break
        if n % k == 1:
            ans += 1
    print(ans)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    solve(N)


if __name__ == '__main__':
    main()

Solution (Python):
def divisor(N:int):
    res = set()
    i = 1
    while i * i <= N:
        if N % i == 0:
            res.add(i)
            if i != N // i:
                res.add(N // i)
        i += 1
    return res

def check(N:int, K:int):
    while N % K == 0:
        N //= K
    return True if N % K == 1 else False

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

    ans = set()
    for K in divisor(N):
        if K == 1: continue
        if check(N, K):
            ans.add(K)

    ans |= divisor(N - 1)

    ans.remove(1)

    print(len(ans))

if __name__ == "__main__":
    main()

Solution (Python):
def divisor(N:int):
    res = set()
    i = 1
    while i * i <= N:
        if N % i == 0:
            res.add(i)
            if i != N // i:
                res.add(N // i)
        i += 1
    return res

def check(N:int, K:int):
    while N % K == 0:
        N //= K
    return True if N == (N // K * K) + 1 else False

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

    ans = set()
    for K in divisor(N):
        if K == 1: continue
        if check(N, K):
            ans.add(K)

    ans |= divisor(N - 1)

    ans.remove(1)

    print(len(ans))

if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
def make_divisors(n):
    mod0 = set()
    mod1 = set()
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            mod0.add(i)
            mod0.add(n/i)
        if (n-1)%i==0:
            mod1.add(i)
            mod1.add((n-1)/i)

    return mod0,mod1

N=list(map(int,(stdin.readline().strip().split())))
num=N[0]
K=0
mod0,mod1=(make_divisors(num))
mod0.remove(1)
mod1.remove(1)
for i in mod0:
    num = N[0]
    while(num % i == 0):
        num/=i

    if num%i==1:
        K+=1
K+=len(mod1)
print(K)

Solution (Python):
from sys import stdin
def make_divisors(n):
    mod0 = set()
    mod1 = set()
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            mod0.add(i)
            mod0.add(n/i)
        if (n-1)%i==0:
            mod1.add(i)
            mod1.add((n-1)/i)

    return mod0,mod1

N=list(map(int,(stdin.readline().strip().split())))
num=N[0]
K=0
mod0,mod1=(make_divisors(num))
mod0.remove(1)
mod1.remove(1)
for i in mod0:
    num = N[0]
    while(num % i == 0):
        num//=i

    if num%i==1:
        K+=1
K+=len(mod1)
print(K)

Solution (Python):
from sys import stdin
def make_divisors(n):
    mod0 = set()
    mod1 = set()
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            mod0.add(i)
            mod0.add(n//i)
        if (n-1)%i==0:
            mod1.add(i)
            mod1.add((n-1)//i)
    return mod0,mod1

N=list(map(int,(stdin.readline().strip().split())))
num=N[0]
K=0
mod0,mod1=(make_divisors(num))
mod0.remove(1)
mod1.remove(1)
for i in mod0:
    num = N[0]
    while(num % i == 0):
        num//=i

    if num%i==1:
        K+=1
K+=len(mod1)
print(K)

Solution (Python):

N = int(input())


def getDivs(n):
    divs = [n]
    for i in range(2, n):
        if i * i > n:
            break
        if n % i == 0:
            divs.append(i)
            if i != n//i:
                divs.append(n//i)
    return divs


if N == 2:
    print(1)
else:
    pf1 = getDivs(N)
    pf2 = getDivs(N-1)
    cnt = len(pf2)

    for x in pf1:
        n = N
        while n%x == 0:
            n //= x
        n %= x 
        
        if n == 1:
            cnt += 1

    
    
    print(cnt)

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

ans = 0

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


ans += len(divisor(N-1))

div_N = divisor(N)

for num in div_N:
    tmp = N
    while tmp % num == 0:
        tmp //= num
    if tmp == 1:
        ans += 1
        continue    
    if (tmp-1) % num == 0:
        ans += 1
print(ans)

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)

    divisors.sort()
    return divisors[1:]

n = int(input())

a = make_divisors(n-1)

b = make_divisors(n)
count = 0

for kk in b:
    mom = n
    while mom % kk == 0:
        mom //= kk
    if mom % kk == 1:
        count +=1

print(len(a) + count)

Solution (Python):
import math
def divs(n):
    res = []
    for i in range(1, n+1):
        if i * i > n:
            break
        if n % i == 0:
            res.append(i)
            if i != n//i:
                res.append(n//i)
    return res

def one(n, k):
    if k == 1:
        return False
    while n % k == 0:
        n //= k
    n %= k
    return n == 1


n = int(input())

ans = sorted(set(divs(n) + divs(n-1)))

ok = 0
for x in ans:
    if one(n, x):
        ok += 1

print(ok)

Solution (Python):
import math


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())

d2 = make_divisors(n - 1)
ans = len(d2)

for k in make_divisors(n):
    if k == 1:
        continue
    tmp = n
    while tmp % k == 0:
        tmp //= k

    if tmp % k == 1:
        d2.append(k)

print(len(d2) - 1)

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())

cnt=len(make_divisors(n-1))-1


lst=make_divisors(n)
for k in lst:
	if k!=1:
		t=n
		while t%k==0:
			t//=k
		if (t-1)%k==0:
			cnt+=1
print(cnt)

Solution (Python):

N=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=set(make_divisors(N-1))
wrong_ans=set(make_divisors(N-1))

K=make_divisors(N)  

for k in K:
    if k==1: continue
    n=N
    while n%k==0:
        n/=k
    else:
        if n==1 or n%k==1:
            ans.add(k)
print len(ans)-1

Solution (Python):

N=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=set(make_divisors(N-1))
wrong_ans=set(make_divisors(N-1))

K=make_divisors(N)  

for k in K:
    if k==1: continue
    n=N
    while n%k==0:
        n/=k
    else:
        
        if n%k==1:
            ans.add(k)
print len(ans)-1

Solution (Python):

N=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=set(make_divisors(N-1))

K=make_divisors(N)  

for k in K:
    if k==1: continue
    n=N
    while n%k==0:
        n/=k
    else:
        
        if n%k==1:
        
            ans.add(k)
print len(ans)-1

Solution (Python):

N=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=set(make_divisors(N-1))

K=make_divisors(N)  

for k in K:
    if k==1: continue
    n=N
    while n%k==0:
        n/=k
    else:
        if n==1 or n%k==1:
            ans.add(k)
print len(ans)-1

Solution (Python):


import sys

sys.setrecursionlimit(10 ** 6)

input_line = input()
inputs = input_line.split(' ')
N, = [int(s) for s in inputs]

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

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

divisors = make_divisors(N)[1:]
for d in divisors:
    t = N
    while t%d==0:
        t = t // d
    if t%d==1:
        num += 1

print(num)

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

def cf(n):
  a=[]
  f=1
  while f*f<=n:
    if n%f==0:
      a.append(f)
      if n//f!=f:
        a.append(n//f)
    f+=1
  return a

def main():
  c=len(cf(N-1))-1
  for f in cf(N):
    t=N
    if f!=1:
      while t%f==0:
        t//=f
      if t%f==1:
        c+=1
  print(c)

main()

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


n = int(input())

ans = 0

for k in enumDivisor(n):
    if k == 1:
        continue
    tmp = n
    while tmp % k == 0:
        tmp //= k
    tmp %= k
    if tmp == 1:
        ans += 1

ans += len(enumDivisor(n - 1)) - 1

print(ans)

Solution (Python):
n = int(input())
if n == 2:
  print(1)
  quit()
elif n == 3:
  print(2)
  quit()
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr
ans = 1
for l in factorization(n-1):
  ans *= (l[1]+1)
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
lst = make_divisors(n)

for i in lst:
  if i == 1 or i == n:
    continue
  m = n
  while m % i == 0:
    m = m // i
  if m % i == 1:
    ans += 1
  
print(ans)

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

def cf(n):
  a=[]
  for f in range(1,int(n**(1/2)+1)):
    if n%f==0:
      a.append(f)
      if n//f!=f:
        a.append(n//f)
  return a

def pf(n):
  a=[]
  while n%2==0:
    a.append(2)
    n//=2
  f=3
  while f*f<=n:
    if n%f==0:
      a.append(f)
      n//=f
    else:
      f+=2
  if n!=1:
    a.append(n)
  return sorted(a)

def main():
  c,p,t=1,N+1,1
  for f in pf(N-1):
    if p==f:
      t+=1
    else:
      c*=t
      t=2
    p=f
  c=c*t-1

  for f in cf(N):
    t=N
    if f!=1:
      while t%f==0:
        t//=f
      if t%f==1:
        c+=1
  print(c)

main()

Solution (Python):
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def devisor(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


def main():
    n = I()

    divs1 = devisor(n)
    divs2 = devisor(n - 1)
    c = len(divs2) - 1
    for val in divs1:
        if val != 1:
            tmp = n
            while tmp % val == 0:
                tmp = tmp // val
            if tmp % val == 1:
                c += 1
    print(c)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
mod0 = set()
mod1 = set()

for i in range(1, int(n**0.5)+1):
    if n%i==0:
        mod0.add(i)
        mod0.add(n//i)
    if (n-1)%i==0:
        mod1.add(i)
        mod1.add((n-1)//i)
mod0.remove(1)
mod1.remove(1)
ans = 0
for i in mod0:
    nn = n
    while nn%i==0:
        nn//=i
    if nn%i==1:
        ans += 1
ans += len(mod1)
print(ans)

Solution (Python):
import collections
def prime_factorize(n):
    a = []
    while n%2 == 0:
        a.append(2)
        n//=2
    f =3
    while f*f <= n:
        if n%f == 0:
            a.append(f)
            n//=f
        else:
            f +=2
    if n != 1:
        a.append(n)
    return a


N = int(input())
factor = collections.Counter(prime_factorize(N-1))
K = 1
for i in list(factor.values()):
    K *= i+1
K -=1
for f in range(2, int(N**0.5)+1):
    n = N
    if n%f != 0:
        continue
    while n%f ==0:
        n//=f
    if n%f ==1 or n==1:
        K+=1

K +=1
print(K)

Solution (Python):
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 sorted(divisors) 
n = int(input())
ans = len(divisors(n-1))-1;
for k in divisors(n)[1:]:
    boz = n
    while (n % k == 0):
        n = n//k
    if (n % k == 1):
	    ans += 1
    n = boz
print(ans)

Solution (Python):
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 sorted(divisors)

N = int(input())

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

for k in divisors(N)[1:]:
    N_ = N
    while N_ % k == 0:
        N_ = N_//k
    if N_ % k == 1:
        ans += 1

print(ans)

Solution (Python):
n=int(input())
if n==2:
    count=1
else:
    count=2
for i in range(2,int(n**0.5)+1):
    if n%i==0:
        k=n//i
        while k>0:
            if k%i==0:
                k=k//i
            else:
                if k%i==1:
                    count+=1
                break
    elif (n-1)%i==0:
        count+=1
        if i!=(n-1)//i:
            count+=1
print(count)

Solution (Python):

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 sorted(divisors)


N = int(input())


count = len(divisors(N - 1)) - 1

for K in divisors(N)[1:]:
    N_ = N
    while N_ % K == 0:
        N_ = N_ // K
    N_ = N_ % K
    if N_ == 1:
        count += 1

print(count)

Solution (Python):
def find_divisors(n):
    divisors = set()
    
    div = 1
    while div ** 2 <= n:
        if n % div == 0:
            divisors.add(div)
            divisors.add(n // div)
        div += 1
    
    return divisors


def main():
    n = int(input())
    
    res = 0
    
    for k in find_divisors(n) - {1}:
        t = n
        while t % k == 0:
            t //= k
        if t % k == 1:
            res += 1
    
    res += len(find_divisors(n - 1)) - 1
    
    print(res)


main()

Solution (Python):
N = int(input())
 
def make_devision(n):
  lst = []
  for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
      lst.append(i)
      if i != n // i:
        lst.append(n // i)
  return lst
 
def calc(n, k):
  if n % k == 0:
    return calc(n // k, k)
  elif n < k:
    return n
  else:
    return calc(n % k, k)
 
ans = make_devision(N-1)
 
for i in make_devision(N):
  if i == 1:
    continue
  if calc(N, i) == 1:
    ans.append(i)
    
print(len(ans)-1)

Solution (Python):



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

def main():
    N=int(input())
    ret=0
    if N==2:
        ret=1
    else:
        div=make_divisors(N)
        div=div+make_divisors(N-1)
        div.append(N)
        div.append(N-1)
        for k in div:
            n=N
            while n%k==0:
                n=n//k
            ret += n%k==1
        if N==2:
            ret = 1
    print(ret)

if __name__ == '__main__':
    main()

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

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

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

for i in range(2, int(n ** 0.5) + 1):
    if n % i == 0:
        k = i
        temp = n
        while temp % k == 0:
            temp //= k
        if temp % k == 1:
            ans.add(k)
        k = n // i
        temp = n
        while temp % k == 0:
            temp //= k
        if temp % k == 1:
            ans.add(k)

print(len(ans) + 2)

Solution (Python):
import sys
import math
N = int(input())
def solve(num):
    d = math.floor(num**(1/2))
    for i in range(1,d+1):
        if num % i == 0:
            yield [i,num//i]

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

cnt = 0
for a,b in solve(N-1):
    if a == b:
        cnt += 1
    else:
        cnt += 2

cnt -= 1

for s in solve(N):
    if s[0] == s[1]:
        s.pop()
    for a in s:
        if a == 1:
            continue

        tmp = N
        while True:
            tmp,m = divmod(tmp, a)
            if m == 0:
                continue
            elif m == 1:
                cnt += 1
            break

print(cnt)

Solution (Python):
from collections import deque

N = int(input())

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

def calc(n, k):
  if n % k == 0:
    return calc(n // k, k)
  elif n < k:
    return n
  else:
    return calc(n % k, k)

ans = make_devision(N-1)

for i in make_devision(N):
  if i == 1:
    continue
  if calc(N, i) == 1:
    ans.append(i)
    
print(len(ans)-1)

Solution (Python):
def divisor(n):
  ret=[]
  for i in range(1,int(n**0.5)+1):
    if n%i==0:
      a,b=i,n//i
      if a!=b:
        ret+=a,
        ret+=b,
      else:
        ret+=a,
  return sorted(ret)

def f(n):
  return divisor(n)[1:]

def solve(n):
  ans=f(n-1)
  for k in f(n):
    N=n
    while N>=k:
      if N%k==0:N=N//k
      else:N=N%k
    if N==1:ans+=k,
  print(len(ans))
  return 0

solve(int(input()))

Solution (Python):
def MI():return map(int,input().split())
def LI():return list(MI())

def factorization(n):
  arr=[]
  temp=n
  for i in range(2,int(n**0.5)+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp//=i
      arr.append([i,cnt])      
  if temp!=1:arr.append([temp,1])
  if arr==[]:arr.append([n,1])
  return arr

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[1:]

n=int(input())

l=[]
for k in make_divisors(n):
  NN=int(n)
  while NN>=k:
    if NN%k==0:
      NN=NN//k
    else:
      NN=NN%k
  if NN==1:l+=k,

ll=(l+make_divisors(n-1))

print(len(ll))

Solution (Python):
from math import sqrt

N = int(input())


def f(x):
    n = N
    while n % x == 0:
        n //= x
    return n % x == 1


ans = 1
for k in range(2, int(sqrt(N)) + 1):
    res = N % k
    if res == 0:
        k1, k2 = k, N // k
        ans += 1 if f(k1) else 0
        ans += 1 if k1 != k2 and f(k2) else 0
    elif res == 1:
        ans += 1 if k == (N - 1) // k else 2
if N >= 3:
    ans += 1

print(ans)

Solution (Python):


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

    def prime_factorize(n):
        res = []
        while n % 2 == 0:
            res.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                res.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            res.append(n)
        return res

    def isqrt(n):
        x = n
        y = (x + 1) // 2
        while y < x:
            x = y
            y = (x + n // x) // 2
        return x

    
    


    ans = 1 
    for i in range(2, isqrt(N-1)+1):
        if (N-1) % i == 0:
            ans += 1
            if i != (N-1) // i:
                ans += 1
    
    
    divs = [N]
    for i in range(2, isqrt(N)+1):
        if N % i == 0:
            divs.append(i)
            j = N // i
            if i != j:
                divs.append(j)
    
    for div in divs:
        M = N
        while M % div == 0:
            M //= div
        if M % div == 1:
            ans += 1
    
    if N == 2:
        ans = 1
    print(ans)

if __name__ == "__main__":
    main()

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

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

def divisior(n):
    a = []
    i = 1
    while (i*i <= n):
        if n%i == 0:
            a.append(i)
            if (i*i != n): a.append(n//i)
        i += 1
    return a

ans = 0
a = divisior(n)

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

b = divisior(n-1)

ans = ans + len(b) -1

print(ans)

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

def divisior(n):
    a = []
    i = 1
    while (i*i <= n):
        if n%i == 0:
            a.append(i)
            if (i*i != n): a.append(n//i)
        i += 1
    return a

ans = 0
a = divisior(n)

for x in a[1:]:
    tmp = n
    while (tmp%x == 0): tmp = tmp//x
    if (tmp%x == 1) : ans += 1

b = divisior(n-1)

ans = ans + len(b) -1

print(ans)

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

def get_divisors(n):
    result = []
    for i in range(1, int(n**.5)+1):
        if n % i == 0:
            result.append(i)
            if n != i ** 2:
                result.append(n // i)
    result.sort()
    return result

c = 0
for number in get_divisors(n)[1:]:
    tmp = n
    while tmp % number == 0:
        tmp //= number
    if tmp % number == 1:
        c += 1

c += len(get_divisors(n-1)) - 1
print(c)

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())
d1 = make_divisors(N)
d2 = make_divisors(N - 1)

ans = len(d2) - 1
for n in d1:
    if n == 1:
        continue
    n2 = N
    while n2 % n == 0:
        n2 //= n
    if n2 % n == 1:
        if n not in d2:
            ans += 1

print(ans)

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

def yakusu(A):
  arr = []
  limit = int(math.sqrt(A))
  for i in range(2,limit+1):
    if A % i == 0:
      arr.append(i)
      if i != A // i:
        arr.append(A//i)
  arr.append(A)
  arr.sort()
  return(arr)

yakusu_N = yakusu(N)
yakusu_N1 = yakusu(N-1)


      
def ope(a,N):
  while True:
    if N % a == 0:
      N = N / a
      if N == 1:
        return 1
        break
    else:
      N = N % a
      if N != 1:
        return 0
        break
      else :
        return 1
        break



count = 0 
for i in yakusu_N:  
  if ope(i,N) == 1:
    count += 1
if N != 2:
  print(count + len(yakusu_N1))
else:
  print(1)

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

n = int(input())
ans = len(divisor(n - 1)) - 1
for i in divisor(n):
    if i == 1:
        continue
    m = n
    while m % i == 0:
        m /= i
    if m % i == 1:
        ans += 1

print(ans)

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, b, ans = make_divisors(n), make_divisors(n-1), 0
for i in range(1, len(a)):
    tmp = n
    while tmp % a[i] == 0:
        tmp = tmp // a[i]
    if (tmp-1) % a[i] == 0:
        ans += 1
ans += len(b)
print(ans-1)

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

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

n = int(input())
l,m,ans = yakusu(n),yakusu(n-1),0
for i in range(1,len(l)):
    a = n
    while a % l[i] == 0:
        a = a // l[i]
    if (a-1) % l[i] == 0:
        ans += 1
ans += len(m)
print(ans-1)

Solution (Python):
def divisors(n):
  small = []
  large = []
  i = 1
  while i * i <= n:
    if not n % i:
      small.append(i)
      large.append(n // i)
    i += 1
  if small[-1] == large[-1]:
    large.pop()
  return small + large[::-1]

n = int(input())
res = set(divisors(n - 1))
res.remove(1)

for d in divisors(n):
  if d == 1:
    continue
  now = n
  
  while not now % d:
    now //= d
  if now % d == 1:
    res.add(d)

print(len(res))

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())
l1=make_divisors(n-1)
l2=make_divisors(n)[2:]
for i in l2:
  j=n/i
  while j%i==0:
    j/=i
  if j%i==1 and n/i not in l1:
    l1.append(n/i)
print(len(l1))

Solution (Python):
import heapq
from collections import defaultdict, deque
from math import ceil, factorial
from fractions import gcd
import sys
sys.setrecursionlimit(10**7)
INF = float('inf')
MOD = 10**9+7

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))


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


n = ii()
ans = 0


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



ans += len(get_divisor(n-1)) - 1

print(ans)

Solution (Python):

import sys

def div(n, k):
    while n % k == 0:
        n //= k
    return n

def solve_slow(N):
    def f():
        ans = 0
        for i in range(2, N+1):
            if div(N, i) % i == 1:
                yield i
    return set(f())

def solve(N: int):
    from itertools import takewhile
    def f():
        for i in takewhile(lambda x: x*x<=N-1, range(1, N)) :
            if (N - 1) % i == 0:
                yield i
                yield (N-1)//i
    def g():
        for i in takewhile(lambda x: x*x<=N, range(2, N)) :
            if N % i == 0:
                if div(N, i) % i == 1:
                    yield i
                if div(N, N // i) % (N // i) == 1:
                    yield N // i
        yield N
    return set(g()) | set(f()) - set([1])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    print(len(solve(N)))

def test():
    for i in range(2, 1000):
        if solve(i) != solve_slow(i):
            print(i, solve(i), _solve(i),)

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))-1
a = make_divisors(N)[1:]
for x in a:
    n = N
    while n%x == 0:
        n //= x
    if n%x == 1:
        ans += 1
print (ans)

Solution (Python):


N=int(input())
cand=[]

def check(N0,K0):
    if N0%K0==0:
        return check(int(N0/K0),K0)
    elif N0%K0==1:
        return 1
    else:
        return 0

def check0(N0,K0):
    while N0%K0==0:
        N0=int(N0/K0)
    if N0%K0==1:
        return 1
    else:
        return 0


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


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


count=0
for i in range(len(cand)):
    if check(N,cand[i]):
        count+=1

print(count)

Solution (Python):
n = int(input())
a = [n]
if n != 2:
    a.append(n - 1)

def div_(N, k):
    while N % k == 0:
        N /= k
    if N % k == 1:
        a.append(k)

for k in range(2, int(n ** 0.5) + 1):
    if n % k == 0:
        div_(n,k)
        if k != n / k:
            div_(n, n // k)

    if (n - 1) % k == 0:
        a.append(k)
        if k != (n - 1) / k:
            a.append((n - 1) // k)

print(len(a))