Problem:
 Score : 500 points    Problem Statement Snuke received a positive integer N from Takahashi.
A positive integer m is called a favorite number when the following condition is satisfied:   The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds.   Find all favorite numbers and print the sum of those.      Constraints  All values in input are integers.  1 \leq N \leq 10^{12}         Input Input is given from Standard Input in the following format:  N       Output Print the answer.        Sample Input 1 8      Sample Output 1 10  There are two favorite numbers: 3 and 7 . Print the sum of these, 10 .       Sample Input 2 1000000000000      Sample Output 2 2499686339916  Watch out for overflow.

Solution (Python):
import math

l = raw_input().split()
N = int(l[0])

def calc(N):
    sum = 0
    for i in range(int(math.sqrt(N))):
        r = i + 1
        q = r
        m = (N - r)/q
        if N - m*q == r and m > q:
            sum += m
            
    return sum





print(calc(N))

Solution (Python):

import itertools
from collections import Counter
from collections import defaultdict
import bisect

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

    ans = 0
    i = 1
    while i * i <= N:
        if N % i == 0:
            opo1 = i - 1
            if opo1 > 0 and N // opo1 == N % opo1:
                ans += opo1
            opo2 = N // i - 1
            if opo2 > 0 and N // opo2 == N % opo2:
                ans += opo2

        i += 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys

input = sys.stdin.readline
n = int(input())
n_div_list = []
for i in range(1, int(n**0.5)+1):
    if n%i == 0:
        if int(n/i) == i:
            n_div_list.append(i)
        else:
            n_div_list.append(i)
            n_div_list.append(int(n/i))
check = 0
cnt = 0
for n_div in n_div_list:
    if n_div - 1 > check:
        cnt += n_div - 1
    check = n_div
print(cnt)

Solution (Python):
n = int(input())
ans = 0
x_max = (n+1/4)**(1/2) - 1/2
for x in range(1, int(x_max + 1)):

    m = (n-x) // x
    if (n-x) % x == 0 and x < m:
        ans += m


print(ans)

Solution (Python):
import math
N = int(input())
ans = 0
k = round(math.sqrt(N))
for i in range(1, k):
    if (N - i) % i == 0:
        ans += (N - i) // i
print("{}".format(ans))

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

N = int(stdin.readline().rstrip())

ans = 0
for k in range(1, int(math.sqrt(N+1))):
    if N % k == 0:
        
        
        ans += ((N//k)-1)

print(ans)

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

N = int(stdin.readline().rstrip())

ans = 0
for k in range(1, int(math.sqrt(N+1))):
    if N % k == 0:
        
        
        ans += ((N//k)-1)

print(ans)

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

for i in range(1,int(math.sqrt(N))+1):
    if N%i == 0 and (N//i)-1 > i:
        ans = ans +  (N//i)-1

print(ans)

Solution (Python):
n = int(input())
ans = 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 = make_divisors(n)
for i in div[1:]:
    if n//(i-1)==n%(i-1):
        ans += i-1

print(ans)

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

for i in range(1,int(math.sqrt(N))+1):
    if N%i == 0 and (N//i)-1 > i:
        ans = ans +  (N//i)-1

print(ans)

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

for i in range(1,int(math.sqrt(N))+1):
    if N%i == 0 and (N//i)-1 > i:
        ans = ans +  (N//i)-1

print(ans)

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

for i in range(1,int(math.sqrt(N))+1):
    if N%i == 0 and (N//i)-1 > i:
        ans = ans +  (N//i)-1

print(ans)

Solution (Python):
N = int(input())
count = 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

if __name__=="__main__":
    lis = make_divisors(N)
    for i in lis:
        if i!= 1:
            if N // (i-1) == N % (i-1):
                count += i-1
    print(count)

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

ls = make_divisors(N)
count =0
for i in ls:
    if N/i -1 >= 1 and i < N/i-1:
        count+= N/i -1 
    

print(int(count))

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def eratosthenes(n):
    p = []
    t = [True] * n

    t[1] = True
    for i in range(2, int(math.ceil(math.sqrt(n)))):
        if t[i]:
            p.append(i)
            for j in range(2*i, n, i):
                t[j] = False

    for j in range(i+1, n):
        if t[j]:
            p.append(j)

    return p


def divisor(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n // i


@mt
def slv(N):
    ans = 0
    for i in divisor(N):
        m = i-1
        if m == 0:
            continue
        if N//m == N % m:
            ans += m
    return ans


def slv2(N):
    ans = 0
    for m in range(1, N+1):

        if N//m == N % m:
            
            print(m, N//m, N % m)
            ans += m
    return ans


def main():
    N = read_int()
    
    print(slv(N))


if __name__ == '__main__':
    main()

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def eratosthenes(n):
    p = []
    t = [True] * n

    t[1] = True
    for i in range(2, int(math.ceil(math.sqrt(n)))):
        if t[i]:
            p.append(i)
            for j in range(2*i, n, i):
                t[j] = False

    for j in range(i+1, n):
        if t[j]:
            p.append(j)

    return p


def divisor(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n // i


@mt
def slv(N):
    ans = 0
    for i in divisor(N):
        m = i-1
        if m == 0:
            continue
        if N//m == N % m:
            ans += m
    return ans


def slv2(N):
    ans = 0
    for m in range(1, N+1):

        if N//m == N % m:
            
            print(m, N//m, N % m)
            ans += m
    return ans


def main():
    N = read_int()
    
    print(slv(N))


if __name__ == '__main__':
    main()

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

ls = make_divisors(N)
count =0
for i in ls:
    if N/i -1 >= 1 and i < N/i-1:
        count+= N/i -1 
    

print(int(count))

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)
    divisors.sort()
    return divisors
  
ans=0
count=1
factor=make_divisors(N)


factor.remove(N)
for f in factor:
  if f==N%((N-f)//f):
    ans+=(N-f)//f
print(ans)

Solution (Python):
import numpy as np
def eratosthenes(n):
    is_prime = np.ones((n+1,), dtype=bool)
    is_prime[:2] = False
    for i in range(2,n+1):
        if is_prime[i]:
            is_prime[i*2::i]=False
    return np.arange(n+1)[is_prime]
Ps = eratosthenes(1000007)
def divisor(n):
    for p in Ps:
        if p*p>n:return -1
        if n%p==0:return p
def prime_division(n):
    d={}
    while n>1:
        p=divisor(n)
        if p==-1:d[n]=d.get(n,0)+1;break
        else:d[p]=d.get(p,0)+1;n//=p
    return d

def z(n,k,v):
    if len(k)==1:
        return [n*k[0]**i for i in range(v[0]+1)]
    else:
        r=[]
        for i in range(v[0]+1):
             r+=z(n*k[0]**i,k[1:],v[1:])
        return r
def y(n):
    pd=prime_division(n)
    KV=[[k,v] for k,v in pd.items()]
    K=[k for k,v in KV]; V=[v for k,v in KV]
    return z(1,K,V)

N=int(input())
if N==1:print(0);exit()
r=0

for yk in y(N):
    if yk>1 and N//(yk-1) == N%(yk-1):
        r+=yk-1
print(r)

Solution (Python):
a = 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


test_list = make_divisors(a)
test_list_modify = [i-1 for i in test_list if i > 2 and a//(i-1) == a%(i-1)]
print(sum(test_list_modify))

Solution (Python):
n = int(input())
ans = 0
for i in range(1,int(n**(1/2))+1):
    s = i
    a = i
    if (n-a)%s==0:
        if (n-a)//s > a:
            ans += (n-a)//s
print(ans)

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

N = int(input())

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

m = int(math.sqrt(N))+1

s, a = divmod(N,m)

sum_of_m = 0
for i in range(s, 0, -1):
    m = N/i - 1
    if m > 0 and m.is_integer() and divmod(N, m) == (i, i):
        sum_of_m += int(m)

print(sum_of_m)

Solution (Python):
n = int(input())
ans = 0
x_max = (n+1/4)**(1/2) - 1/2
for x in range(1, int(x_max + 1)):

    m = (n-x) // x
    if (n-x) % x == 0 and x < m:
        ans += m


print(ans)

Solution (Python):
N = long(raw_input())

prime_factor = []

all_sum = 0

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

print all_sum

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

for i in range(1,int(math.sqrt(N))+1):
    if N%i == 0 and (N//i)-1 > i:
        ans = ans +  (N//i)-1

print(ans)

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

for i in range(1,int(math.sqrt(N))+1):
    if N%i == 0 and (N//i)-1 > i:
        ans = ans +  (N//i)-1

print(ans)

Solution (Python):
def solve(N):
    s = 1
    e = int(pow(N, 0.5)) + 1
    ds = []
    for i in range(s, e):
        if N % i == 0:
            m = (N // i) - 1
            if m and N // m == N % m:
                ds.append(N // i)
                

    return sum([i - 1 for i in ds])


assert (solve(8) == 3 + 7)
assert (solve(10) == 4 + 9)
assert (solve(1000000000000) == 2499686339916)
if __name__ == "__main__":
    N = int(input())
    print(solve(N))

Solution (Python):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())

n = ni()
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

lis = make_divisors(n)
ans = 0
for i in lis:
    if i - 1 == 0:
        continue
    if i - 1 > n // i:
        ans += i - 1
print(ans)

Solution (Python):
n=int(input())
ans=0
i=0
while True:
    i+=1
    if (n-i)//i<i:
        break
    elif n%((n-i)//i)==i:
        ans+=(n-i)//i
print(ans)

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

if N > 2:
    ans = N - 1
else:
    ans = 0

x = 2
while x*x <= N:
    if N % x == 0:
        m = N // x - 1
        if N % m == x:
            ans += m
    x += 1
print(ans)

Solution (Python):
import math
N = int(input())
ans = 0
n_max = int(math.sqrt(N))
for n in range(1,n_max+1):
	if N%n == 0:
		a = N//n
		if a+1 < n:
			ans += n-1
		elif n+1 < a:
			ans += a-1
print(ans)

Solution (Python):


import math
import re

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 main(params):
    n = params
    a = make_divisors(n)
    total = 0
    for i in a:
        if i - 1 >= 2 and i -1 > n  / i:
            total += i - 1
    print total

if __name__ == "__main__":
    params = int(raw_input())
    




    main(params)

Solution (Python):
import collections
N = int(input())
ans = 0


def prime_decomposition(n):
    i = 2
    ret = collections.defaultdict(int)
    while i * i <= n:
        while n % i == 0:
            n //= i
            ret[i] += 1
        i += 1
    if n > 1:
        ret[n] = 1
    return ret


factors_dict = prime_decomposition(N)
factors_values = list(factors_dict.values())
factors_keys = list(factors_dict.keys())
factors = []
import itertools
for K in itertools.product(*[range(_ + 1) for _ in factors_values]):
    f = 1
    for i in range(len(factors_keys)):
        f *= factors_keys[i]**K[i]
    factors += [f]
ans = 0
for f in factors:
    if N < f * (f - 1):
        ans += f - 1
print(ans)

Solution (Python):
import math
N=int(input())
rt = int(math.sqrt(N))


res = 0
for a in range(1, rt+1):
    if N % a == 0:
        b1 = N // a
        b = b1-1 
        if b > a and b > 0:
            res += b

print(res)

Solution (Python):
import math
N = int(input())
ans = 0
n_max = int(math.sqrt(N))
for n in range(1,n_max+1):
	if N%n == 0:
		a = N//n
		if a+1 < n:
			ans += n-1
		elif n+1 < a:
			ans += a-1
print(ans)

Solution (Python):
def main():
    n = int(input())
    res = 0
    if n<=8:
        for i in range(1,n):
            if n//i == n%i:
                res += i
    else:
        for i in range(1,int(n**(1/2))):
            if (n-i)/i == (n-i)//i and (n-i)//i>0:
                res += (n-i)//i
    print(res)
if __name__ == '__main__':
    main()

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

for i in range(1,int(math.sqrt(N))+1):
    if N%i == 0 and (N//i)-1 > i:
        ans = ans +  (N//i)-1

print(ans)

Solution (Python):
n=int(input())
ans=0
i=0
while True:
    i+=1
    if (n-i)//i<i:
        break
    elif n%((n-i)//i)==i:
        ans+=(n-i)//i
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)
    divisors.sort()
    return divisors
  
ans=0
count=1
factor=make_divisors(N)


factor.remove(N)
for f in factor:
  if f==N%((N-f)//f):
    ans+=(N-f)//f
print(ans)

Solution (Python):
N = int(input())
ans = 0
if N <= 2:
    print(0)
    exit()
for i in range(1, 10**6):
    if (N - i) % i == 0:
        tmp = (N - i) // i
        if tmp > 1 and tmp > i:
            ans += tmp
print(ans)

Solution (Python):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())

n = ni()
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

lis = make_divisors(n)
ans = 0
for i in lis:
    if i - 1 == 0:
        continue
    if i - 1 > n // (i - 1):
        ans += i - 1
print(ans)

Solution (Python):
import math

n = int(input())


sum_fav = 0
for s in range(1,int(math.sqrt(n))+1):
  if n%s == 0:
    m = n//s-1
    if s < m:
      
      sum_fav += m
    else:
      break
  
print(sum_fav)

Solution (Python):
N = int(input())
ans = 0
if N <= 2:
    print(0)
    exit()
for i in range(1, 10**7):
    if (N - i) % i == 0:
        tmp = (N - i) // i
        if tmp > 1 and tmp > i:
            ans += tmp
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)
            
            divisors.append(n//i)
    return divisors


num = 0
div = make_divisors(N)

'''
for i in range(0,len(div)-1,2): 
    if div[i+1]+1-div[i] >= 2 and div[i+1]+1-div[i] <= div[i+1]:
        num += div[i+1]-1
'''
for i in range(0,len(div)-1,2): 
    if div[i] <= div[i+1]-2:
        num += div[i+1]-1
        


print(num)

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

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

print(ans)

Solution (Python):

n = int(input())

m_sum = 0
for i in range(1, n):
    m = n / i - 1
    if i >= m:
        break

    int_m = int(m)
    if m == int_m:
        m_sum += int_m

print(m_sum)

Solution (Python):






N = int(input())
answer = 0

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

print(answer)

Solution (Python):
N = int(input())
ans = 0
if N <= 2:
    print(0)
    exit()
for i in range(1, 10**7):
    if (N - i) % i == 0:
        tmp = (N - i) // i
        if tmp > 1 and tmp > i:
            ans += tmp
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)
    divisors.sort()
    return divisors
  
ans=0
count=1
factor=make_divisors(N)


factor.remove(N)
for f in factor:
  if f==N%((N-f)//f):
    ans+=(N-f)//f
  
print(ans)

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

i = 2
N_ = N
ans = 0

divisor = {}
for i in range(2,N):
    if N_ % i == 0:
        divisor[i] = 0
        while(N_ % i == 0):
            divisor[i] += 1
            N_  //= i

    if i *i > N_:
        if N_ != 1:
            if N_ in divisor.keys():
                divisor[N_] += 1
            else:
                divisor[N_] = 1
        break

ans += 0
def solve(dic,keys,n,i):
    if i == len(keys):

        if n-1 != 0 and N == (N % (n-1))*n:
            global ans
            ans += n-1

    else:
        for j in range(dic[keys[i]]+1):
            solve(dic,keys,n*keys[i]**j,i+1)


ans = 0 
solve(divisor,list(divisor.keys()),1,0)
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
ans = 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

yaku = make_divisors(N)
if int(N**(1/2))*(int(N**(1/2))+1) == N:
	for i, num in enumerate(sorted(yaku)):
		if i == len(yaku)//2-1:
			break
		ans += N//num-1
	print(ans)
else:
	for i, num in enumerate(sorted(yaku)):
		if i == len(yaku)//2:
			break
		ans += N//num-1
	print(ans)

Solution (Python):

from heapq import heappush, heapreplace
from itertools import count, chain, cycle
from functools import partial
from math import floor, ceil, sqrt
from fractions import gcd
from collections import defaultdict, deque

def Primes_fnct():
    def b_search(L,t):
        
        search_range = [-1, len(L)]
        update_range = lambda mid: search_range.__setitem__(t<L[mid], mid)
        for _ in [0]*search_range[1].bit_length():
            update_range(sum(search_range)//2)
        return search_range[0]
    
    P = [2,]
    Pappend = P.append
    Q = deque([])
    Qappend = Q.append
    Qpopleft = Q.popleft
    hq = [] 
    integer = count(3,2)
    current_i = 1
    valid_range = 1
    def Primes(*, max_int=None):
        nonlocal valid_range, current_i
        if max_int is None:
            return P[:]

        if  max_int - current_i <= 1:
            return P[:b_search(P,max_int)+1]

        for i in integer:
            if i >= valid_range:
                if Q:
                    q = Qpopleft()
                    heappush(hq, (q**2,q))
                valid_range = Q[0]**2 if Q else i**2

            m,r = hq[0] if hq else (0,0)
            if i != m:
                Pappend(i)
                Qappend(i)

            while m == i:
                heapreplace(hq, (m+2*r, r))
                m,r = hq[0]

            current_i = i
            if max_int - current_i <=1:
                break 
        return P[:]
    return Primes

def factorization(m, Primes=None):
    F = defaultdict(int)
    if m < 2:
        return F

    while not m&1:
        F[2] += 1
        m >>= 1

    if Primes is None:
        Primes = Primes_fnct()

    Primes = deque(Primes(max_int=ceil(sqrt(m))+1))
    Primespopleft = Primes.popleft

    while m > 1 and Primes:
        p = Primespopleft()
        while not m%p:
            m //= p
            F[p] += 1

    if m > 1:
        F[m] += 1
    return F

def solve():
    N = int(input())
    F = factorization(N)
    Q = sorted(F.items())
    P = [q[0] for q in Q]
    I = [q[1] for q in Q]
    i = [0 for _ in range(len(P)+1)]
    m = 1
    res = 0
    while any(a<b for a,b in zip(i,I)):
        if i[0] < I[0]:
            i[0] += 1
            m *= P[0]
        else:
            for j in range(0, len(P)):
                if i[j] < I[j]:
                    i[j] += 1
                    m *= P[j]
                    break
                else:
                    m //= P[j]**i[j]
                    i[j] = 0
        if N%(m-1) == N//(m-1):
            res += (m-1)

    return str(res)

if __name__ == '__main__':
    print(solve())

Solution (Python):
from itertools import product

N = int(input())

sqrt = int(N ** 0.5)

factorize_result = {}
n = N
for i in range(2, sqrt + 1):
    if n % i == 0:
        factorize_result[i] = 1
        n = n // i
        while n % i == 0:
            factorize_result[i] += 1
            n = n // i
if n > 1:
    factorize_result[n] = 1

ans = 0
vs = [list(range(v+1)) for v in factorize_result.values()]
for indices in product(*vs, repeat=1):

    tmp = 1
    for i, (k, v) in enumerate(factorize_result.items()):
       tmp *= k ** indices[i]

    tmp -= 1
    if tmp == 0:
        continue

    if N % tmp == N // tmp:
        ans += tmp

print(ans)

Solution (Python):
import numpy as np
N = int(input())

Number_to_divide = []
for i in range(1,int(np.sqrt(N))+1):
    if (N % i == 0)and((N / i) > (i + 1)):
        Number_to_divide.append((N / i) - 1)
print(int(sum(Number_to_divide)))

Solution (Python):

import numpy as np
from functools import lru_cache
import time
import math

def main(): 
    if True:
        N = int(input())
        
        
    else:
        pass

    sN = int(math.sqrt(N))
    r = np.asarray([],dtype=int)
    count = 0
    for i in range(sN+1):
        
        if N % (i+1) == 0 :
            r = np.append(r,i+1)
            if i+1 != N//(i+1):
                r = np.append(r,N//(i+1))
    r = np.sort(r)

    for i in range(r.size)[1:]:
        if N//(r[i]-1) == N%(r[i]-1):
            count += r[i]-1
        else:
            pass
            

    print(int(count))
if __name__ =='__main__':
    main()

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

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

print(ans)

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

sum = 0
for i in range(1, int(n**0.5) + 1):
    if n == 1:
        break
    if n % i == 0 and n // i - 1 > i:
        sum = sum + n // i - 1

print(sum)

Solution (Python):
import numpy as np
N = int(input())

Number_to_divide = []
for i in range(1,int(np.sqrt(N))+1):
    if (N % i == 0)and((N / i) > (i + 1)):
        Number_to_divide.append((N / i) - 1)
print(int(sum(Number_to_divide)))

Solution (Python):
def makeDiv(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)
    div.sort()
    return div

N = int(input())
L = makeDiv(N)
ans = 0
shou = 0
for i in L:
    shou = (N-i)//i
    if shou > i and N == shou*i+i and shou != 1:
        ans += shou
print(ans)

Solution (Python):
import math

N = int(input())
m = int(math.sqrt(N))
ans = 0
for j in range(1, m + 1):
    if N % j == 0:
        q = N // j
        if q - 1 > j:
            ans += N // j - 1
print(ans)

Solution (Python):
N = int(input())
yakusuu = []

for i in range(1, int(N**0.5) + 1):
    if N % i == 0:
        yakusuu.append(i - 1)
        yakusuu.append(N // i - 1)
retval = 0
for y in yakusuu:
    if y == 0:
        continue
    if N // y == N % y:
        retval += y

print(retval)

Solution (Python):
N = int(input())
ans = 0
x = 0

while x**2+x < N:
    x += 1
    m = (N-x)/x
    if m % 1 == 0:
        if x < m <= N:
            ans += m
        else:
            break

print(int(ans))

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

imax = int(n**(1/2))+1
cnt = 0
for i in range(1,imax):
    if (n-i)%i == 0:
        if i >= (n-1)//i:
            continue
        cnt += (n-i)//i
print(cnt)

Solution (Python):
n = int(input())
ans = 0
for r in range(1, int(1e6) + 1):
    if n <= r * r:
        break
    m = (n - r) // r
    if n % m == n // m:
        ans += m
print(ans)

Solution (Python):
n = int(input())
i = 1
r = []
while((n-i)/i>i):
  if (n-i)%i==0:
    r.append(i)
  i+=1
print(sum([int((n-j)/j) for j in r]))

Solution (Python):
import numpy as np
N = int(input())

Number_to_divide = []
for i in range(1,int(np.sqrt(N))+1):
    if (N % i == 0)and((N / i) > (i + 1)):
        Number_to_divide.append((N / i) - 1)
print(int(sum(Number_to_divide)))

Solution (Python):
import math
N=int(input())
rt = int(math.sqrt(N))


res = 0
for a in range(1, rt+1):
    if N % a == 0:
        b1 = N // a
        b = b1-1 
        if b > a and b > 0:
            res += b

print(res)

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

co = 0
i = 1
while True:
	if (n - i) // i <= i:
		break
	if (n - i) % i == 0:
		co += (n - i) // i
	i += 1
print(co)

Solution (Python):
import math

n = int(input())


sum_fav = 0
for s in range(1,int(math.sqrt(n))+1):
  if n%s == 0:
    m = n//s-1
    if s < m:
      
      sum_fav += m
    else:
      break
  
print(sum_fav)

Solution (Python):
import math

N = int(input())

ans = 0
for i in range(1, int(math.sqrt(N)) + 1):
  if i > N / 2:
    continue
  tmp = int((N - i) / i)
  if (N - i) % i == 0 and N % tmp != 0 and tmp >= math.sqrt(N):
    ans += tmp

print(ans)

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

s = 0
m = 1
while True:
    n = N - m
    x = n//m
    if m >= x:
        break
    if n % m == 0:
        s += x
    m += 1

print(s)

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

if N > 2:
    ans = N - 1
else:
    ans = 0

x = 2
while x*x <= N:
    if N % x == 0:
        m = N // x - 1
        if N % m == x:
            ans += m
    x += 1
print(ans)

Solution (Python):
import collections
N = int(input())
ans = 0


def prime_decomposition(n):
    i = 2
    ret = collections.defaultdict(int)
    while i * i <= n:
        while n % i == 0:
            n //= i
            ret[i] += 1
        i += 1
    if n > 1:
        ret[n] = 1
    return ret


factors_dict = prime_decomposition(N)
factors_values = list(factors_dict.values())
factors_keys = list(factors_dict.keys())
factors = []
import itertools
for K in itertools.product(*[range(_ + 1) for _ in factors_values]):
    f = 1
    for i in range(len(factors_keys)):
        f *= factors_keys[i]**K[i]
    factors += [f]
ans = 0
for f in factors:
    if N < f * (f - 1):
        ans += f - 1
print(ans)

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

ans = 0
for i in range(1,n):
    if (n-i)/i > i:
        if (n-i)%i == 0:
            ans += (n-i)/i
    else:
        break
print(int(ans))

Solution (Python):
import math

n = int(input())


sum_fav = 0
for s in range(1,int(math.sqrt(n))+1):
  if n%s == 0:
    m = n//s-1
    if s < m:
      
      sum_fav += m
    else:
      break
  
print(sum_fav)

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

N = int(input())
l = make_divisors(N)
g = 0
for c in l:
    rc = N//c - 1
    if (rc != 0):
        if (N % rc) == (N//rc):
            g+=rc
print(g)

Solution (Python):
N = int(input())
num = 0
for i in range(1,int(N**0.5)+1):
  m = N//i-1
  if m!=0 :

    if (N//m) == (N % m):num += m
print(num)

Solution (Python):
import math
N = int(input())
ans = 0
s = math.sqrt(N)
for i in range(1, math.ceil(s)):
  if N%i == 0:
    a = N/i - 1
    if a > i:
      ans += a
    else:
      break;
print(int(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

N = int(input())
l = make_divisors(N)

g = 0
for c in l:
    rc = N//c - 1
    if (rc != 0):
        if (N % rc) == (N//rc):
            g+=rc
            
print(g)

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

sum = 0
for i in range(1, int(n**0.5) + 1):
    if n == 1:
        break
    if n % i == 0 and n // i - 1 > i:
        sum = sum + n // i - 1

print(sum)