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 sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def main():
    N = int(readline())
    div = divisors(N)
    ans = 0
    for m in div:
        if m!=1:
            if N//(m-1) == N%(m-1):
                ans += m-1
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
l=[]
if n==1 or n==2:
    print(0)
    exit()
for i in range(1,int(n**0.5)+1):
    if n%i==0 and n//i-i>1:
        l.append(n//i)

print(sum(l)-len(l))

Solution (Python):
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(input())
ans = 0

yakusu = make_divisors(n)

for i in yakusu:
    if i != 1 and (n//(i-1) == n%(i-1)):
        ans += i-1

print(ans)

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

import math  
  

def printDivisors(n) : 
	list = []  
	for i in range(1, int(math.sqrt(n) + 1)) : 
		if (n % i == 0) : 
			if (n / i == i) : 
				list.append(i) 
			else : 
				list.append(i) 
				list.append(int(n / i)) 
	return(list)

A = printDivisors(N)

for i in range (1, len(A)):
	if N//(A[i]-1) == N/A[i]:
		count+=(A[i]-1)

print(count)

Solution (Python):
def main():
    import sys

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

    n = int(input())
    i = 1
    ans = 0
    while i*i < n:
        if n%i == 0:
            tmp = n//i -1
            if i < tmp:
                ans += n//i - 1
        i+= 1
    print(ans)




    
if __name__ == '__main__':
    main()

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def enum_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():
    n = int(readline())
    divs = enum_divisors(n)
    ans = 0

    for x in divs:
        m = n // x - 1
        if n - m * x < m:
            ans += m

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
c = 1
li = []
while True:
    k = n-c
    if k//c <= c:
        break
    if k % c == 0:
        li.append(k//c)
    c += 1
print(sum(li))

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

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

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
n = int(input())
ans = 0
def calc(x):
    x -= 1
    if x <= 0:
        return 0
    elif n // x == n % x:
        return x
    return 0

for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        ans += calc(n // i) + calc(i)
print(ans)

Solution (Python):






























































N = int(input())
if N <= 2:
    print(0)
    exit()
ans = N - 1
div = 2
limit = N // div
while div <= limit:
    tmp = limit
    
    while True:
        if N % tmp > div or tmp <= N // (div + 1):
            break
        if N % tmp == div:
            ans += tmp
            break
        tmp -= 1
    div += 1
    limit = N // div
print(ans)

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

if n == 1:
  print(0)
  quit()

for i in range(1, n):
  
  
  temp=n-i
  syou=temp/i
  if syou>i:
    if syou.is_integer():
      ans+=int(syou)
  else:
    break
print(ans)

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

if n == 1:
  print(0)
  quit()

for i in range(1, n):
  
  
  temp=n-i
  syou=temp/i
  if syou>i:
    if syou.is_integer():
      ans+=int(syou)
  else:
    break
print(ans)

Solution (Python):
n = int(input())
ans=0
if n == 1:
  print(0)
  quit()






  
for i in range(1, n):
  
  temp=n-i
  syou=temp/i
  
  if syou>i:
    if syou.is_integer():
      ans+=int(syou)
  else:
    break
print(ans)

Solution (Python):
n=int(input())
x=10**12
i=1
c=0
while x>i+1:
  x=(n-i)//i
  if (n-i)%i==0 and n-i!=i:c+=x
  i+=1
print(c)

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = sorted(list(set(table)))
    return table

n = INT()
a = divisor(n)
ans = 0
for x in a:
    if n // x <= x - 2:
        ans += x - 1
print(ans)

Solution (Python):
n=int(input())
print(sum([n//x-1 for x in range(1,int(n**.5)+1) if n%x==0 and n//x-1>x]))

Solution (Python):
def div(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(input())
lis = list(set(div(n)))
ans = 0
for b in lis:
    c = b - 1
    if c != 0:
        
        if n//c == n%c:
            ans += c
print(ans)

Solution (Python):
def solve(n):
    res = 0
    p = 1
    while p**2 <= n:
        if n % p == 0:
            m = n // p - 1
            if m > p:
                res += m
        p += 1
    return res

n = int(input())
print(solve(n))

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

divs=make_divisors(n)
ans=0
for div_i in divs:
    k=div_i
    m=(n-k)//k
    if m>k:
        ans+=m
print(ans)

Solution (Python):
def make_divisors(n):
    ret = []
    d = 1
    while d * d <= n:
        if n % d == 0:
            ret.append(d)
            if d != n // d:
                ret.append(n // d)
        d += 1
    return ret


def test(n):
    ret = 0
    for i in range(1, n + 1):
        if n // i == n % i:
            ret += i
    return ret


def main(n):
    d = make_divisors(n)
    
    ans = 0
    for i in d:
        m = i - 1
        if 1 <= n // (m + 1) < m:
            ans += m
    return ans
    

n = int(input())
print(main(n))

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

Solution (Python):
N = int(input())
x,r = 1,0

while x*x < N:
	if N%x==0:
		if x>1 and N//(x-1)==N%(x-1):
			r += x-1
		t = N//x-1
		if N//t==N%t:
			r += t
	x += 1

print(r)

Solution (Python):
def make_divisors(n):
    
    l, u = [], []
    i = 1
    while i*i<=n:
        if n%i==0:
            l.append(i)
            if i!=n//i:
                u.append(n//i)
        i+=1
    return l+u[::-1]

n = int(input())
Ns = make_divisors(n)
Ns = [_ns-1 for _ns in Ns if _ns!=1]
ans = 0
for _ns in Ns:
    if n//_ns==n%_ns:
        ans += _ns
print(ans)

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

i = 1
rlt = 0
while N > i**2 + i:
  if (N-i)%i == 0:
    rlt += (N-i)//i
  i += 1
    
print(rlt)

Solution (Python):
def make_divisors(n):
    lw, up = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lw.append(i)
        if i * i != n:
            up.append(n//i)
        i += 1
    return lw + up[::-1]

N = int(input())
ans = 0
li = make_divisors(N)
if N == 1 or N==2:
    print(0)
    exit()

for x in li:
    if x * (x+2) > N:
        break
    ans += N//x - 1
print(ans)

Solution (Python):
N = int(input())
i = 1
ans = 0
while i*i<N:
    temp = N//i-1
    if  N == i*temp+i and (N-i)/i > i:
        ans += temp
    i+=1
print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



N = INT()

ans = 0
m = INF
r = 1

while r < m:
	m = (N-r)/r
	if (N-r)%r == 0 and r < m:
		ans += m
	r += 1

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)
    return divisors

N = int(input())
divisors = make_divisors(N)
ans = 0
divisors.sort(reverse=True)
for x in divisors:
    if x > 1:
        temp = x - 1
        d,m = divmod(N,temp)
        if d != m:
            break
        else:
            ans += temp
print(ans)

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

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

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

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

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


ans = 0

for i in range(1, 1000000):
    if N <= i:
        break
    
    

    if (N - i) % i == 0:
        a = (N-i) // i
        if a <= i:
            break
        ans += a
        

print(ans)

Solution (Python):
n = int(input())
from math import gcd
cou = 0
for i in range(1,int(n**0.5)+1):
  if n%i==0:
    b = n//i-1
    if b>=2 and n//b==n%b:
      cou += b
    
    if i>2:
      c = i-1
      if n//c==n%c:
        cou += c
print(cou)

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

D = make_divisors(n)
ans = 0
for d in D:
    m = d-1
    q = n//d
    if m > 0 and 0 <= q < m:
        ans += m
print(ans)

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
ans=0
for i in range(1,n+1):
    
    if (n-i)%i==0 and i<(n-i)//i:
        ans+=((n-i)//i)
        
    if (n-i)+100<i**2:
        
        break
    
print(ans)

Solution (Python):
def divisor(n):
  cd = []
  i = 1
  while i*i <= n:
    if n%i==0:
      if i*(i-1)>N:
        cd.append(i-1)
      if i != n//i and (n//i)*(n//i-1)>N:
        cd.append(n//i-1)
    i += 1
  return cd

N = int(input())
print(sum(divisor(N)))

Solution (Python):
N = int(input())
A = []
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        a = i
        b = N//i
        if a>b:
            a,b = b,a
        if 0<a<b-1:
            A.append(b-1)
print(sum(A))

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter



import bisect
n=int(input())
if n==1:
    print(0)
    exit()
elif n==2:
  print(0)
  exit()
m=math.ceil(n/((n-1)**0.5+1))
ans=0
for i in range(1,m):
    if n%i==0:
        ans+=(n//i-1)
print(ans)

Solution (Python):
N = int(input())
lim = int(N ** 0.5)
ans = 0
for i in range(1, lim + 1):
    m = N // i
    quotient = N // m
    while m != 0:
        remainder = N % m
        if N // m != quotient or remainder > i:
            break
        if quotient == remainder:
            ans += m
            break
        m -= 1
print(ans)

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


def main():
    N = in_n()
    yaku = make_divisors(N)

    ans = 0
    for n in yaku:
        if n < N // n - 1:
            ans += N // n - 1

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

def divisor_dif_2_over(n):
    if n == 1:
        return []
    res = []
    i = 1
    while i * i <= n:
        if n % i == 0 and (n // i) - i >= 2:
            res.append(n // i - 1)
        i += 1
    return res


n = int(input())

print(sum(divisor_dif_2_over(n)))

Solution (Python):
def factor(N):
    arr=[]
    for i in range(1,int(N**0.5)+1):
        if(N%i==0):
            arr.append(i)
            if(N//i!=i):
                arr.append(N//i)
    return arr
N=int(input())
arr=factor(N)
ans=0
for x in arr:
    m=N//x-1
    if m<=x:
        continue
    ans+=m
print(ans)

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    sum = 0
    for i in range(1,10**6):
        if i**2 >= n:
            break
        if n%i == 0:
            if i < n//i-1:
                sum += n//i-1
            else:
                break
    print(sum)
    return None

if __name__ == '__main__':
    main()

Solution (Python):

from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def cal_divisors(N):
    divisors = []
    i = 1
    while i*i < N:
        if N % i == 0:
            divisors.append(i)
        i += 1
    divisors.sort()
    return divisors

def main():
    N = int(input())
    l = cal_divisors(N)
    ans = 0
    for i in l:
        if N//i - i > 1:
            ans += N//i - 1
    print(ans)

if __name__ == "__main__":
    main()

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

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

def main():
    mod=10**9+7
    N=I()
    N2=int(N**0.5)+5
    
    ans=0
    for i in range(1,N2):
        m=(N-i)//i
        if m*i+i==N:
            if i<m:
                ans+=m
                
    print(ans)

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**2 == n:
                continue
            ass.append(n//i)
    ass.sort()
    return ass 


def main():
    N = int(input())
    if N <= 2:
        print(0)
        exit()
    ans = 0
    for i in divisor(N):
        if i == 1:
            continue
        if N // (i-1) == N % (i-1):
            ans += (i-1)

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):


import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union































def main():
    Num = Union[int, float]
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    def enum_divisor(num: int) -> List[int]:
        '''
        O(√n) で約数列挙を行う
        >>> enum_divisor(4)
        [1, 2, 4]
        >>> enum_divisor(19)
        [1, 19]
        >>> enum_divisor(100)
        [1, 2, 4, 5, 10, 20, 25, 50, 100]
        '''
        if num < 1:
            raise ValueError(f'enum_divisor(): argument should be >= 1. got {num}')    
        divisor_small = []
        divisor_large = []
        i = 1
        while i ** 2 <= num:
            if num % i == 0:
                divisor_small.append(i)
                if i != num // i:
                    divisor_large.append(num // i)
            i += 1
        divisor_large.reverse()
        return divisor_small + divisor_large


    n = ii()
    ans = 0
    divisor = enum_divisor(n)
    for num in divisor:
        if num <= 2:
            continue
        r = n // num
        m = num - 1
        if 1 <= r <= m - 1:
            ans += m
    
    print(ans)



if __name__ == "__main__":
    main()

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

for i in range(1,int(n**0.5)+1):
    if n//i == n%i:
        s.add(i)
    x = (n-i)//i
    if x and n//x == n%x:
        s.add(x)
print(sum(list(s)))

Solution (Python):
def factor(N):
    res = []
    for i in range(1,int(N**0.5)+1):
        if N%i == 0:
            res.append(i)
            res.append(N//i)
    return sorted(list(set(res)))

N = int(input())
f = factor(N)
f.pop(0)

ans = 0
for n in f:
    tmp = n-1
    if N//tmp == N%tmp:
        ans += tmp
        
print(ans)

Solution (Python):

def Prime_Factorization(n):
    R=[]
    N=n

    for k in range(2,int(-(-n**0.5//1))+1):
        if N%k==0:
            C=0
            while N%k==0:
                C+=1
                N//=k
            R.append([k,C])

    if N!=1:
        R.append([N,1])
        
    if not R:
        R.append([N,1])

    return R


from copy import copy
def Divisors(n):
    if n==1:
        return [1]
    
    L=Prime_Factorization(n)
    U=[1]

    for (p,k) in L:
        T=copy(U)
        for t in T:
            r=t
            for _ in range(1,k+1):
                r*=p
                U.append(r)
    U.sort()
    return U


import sys
N=int(input())
if N==1:
    print(0)
    sys.exit()
    
L=Divisors(N)
L.remove(1)

K=0
for a in L:
    b=a-1
    if N//b==N%b:
        K+=b
print(K)

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

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

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

Solution (Python):
import unittest


def solve_small(n):
    total = 0
    for m in range(1, n):
        if n // m == n % m:
            total += m
    return total


def solve(n):
    if n == 1:
        return 0
    conds = set()
    conds.add(n-1)
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            conds.add(i-1)
            conds.add(n // i - 1)
    total = 0
    for m in list(conds):
        if n // m == n % m:
            total += m
    return total


def main():
    n = int(input())
    result = solve(n)
    print(result)


if __name__ == "__main__":
    main()


class Test(unittest.TestCase):
    def test_solve_1(self):
        n = 8
        actual = solve(n)
        expected = 10
        self.assertEqual(actual, expected)

    def test_solve_2(self):
        n = 1000000000000
        actual = solve(n)
        expected = 2499686339916
        self.assertEqual(actual, expected)

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


divs = make_divisors(N)

s = set()
for div in divs:
    if div == 1:
        continue
    a, b = divmod(N, div - 1)
    if a == b:
        s.add(div - 1)

print(sum(s))

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

def makediv(n):
	lower_divisors , upper_divisors = [], []
	i = 1
	while i*i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n//i)
		i += 1
	return lower_divisors + upper_divisors[::-1]

ans = 0
for i in makediv(n):
	targ = i-1
	if targ != 0:
		if n // targ == n % targ:
			ans += targ
print(ans)

Solution (Python):
N=int(input())
ans=N-1 if 3<N else 0
for a in range(2,int(N**0.5)+1):
    if N%a== 0 and N//a != a:
        b = N//a-1
        if N%b==N//b:
            ans+=b
print(ans)

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

def makediv(n):
	lower_divisors , upper_divisors = [], []
	i = 1
	while i*i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n//i)
		i += 1
	return lower_divisors + upper_divisors[::-1]

k = makediv(n)

ans = 0
for i in k:
	targ = i-1
	if targ != 0:
		if n // targ == n % targ:
			ans += targ

print(ans)

Solution (Python):
from math import sqrt
from math import ceil
from collections import defaultdict
N=int(input())
done=defaultdict(int)
ans=0

for i in range(1,ceil(sqrt(N))+1):
    if N//i == N%i:
        if done[i]==0:
            ans+=i
            
            done[i]=1
    if (N-i)%i==0:
        if done[(N-i)//i]==0 and (N-i)//i>i:
            ans+=(N-i)//i
            
            done[(N-i)//i]=1
print(ans)

Solution (Python):
def divG(n) -> list:
    if n == 0:
        return [0]
    i = 1
    table = set()
    while i * i <= n:
        if n % i == 0:
            table |= {(n // i - 1) * (i < n // i - 1)}
        i += 1
    return table
print(sum(divG(int(input()))))

Solution (Python):
n=int(input())
p=0
for i in range(1,int(n**0.5)+10):
    if n%i==0 and n//i-1>i:
        p+=n//i-1
print(p)

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

n = int(input())
ans = 0
for i in divisor(n):
    if i == 1: continue
    m = i-1
    p,r = divmod(n,m)
    if p == r: ans += m
print(ans)

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


N = int(input())
ans = 0
for i in enum_divisors(N):
    d = N // i - 1
    if d == 0 or N // d != N % d:
        continue
    ans += d
print(ans)

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

ans = 0
for div in range(1, int(n ** 0.5) + 1):
    if (n - div) % div == 0 and div < (n - div) // div:
        ans += (n - div) // div

print(ans)

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

divisors = set()
for i in range(1, int(n**.5)+1):
    if n % i == 0:
        divisors |= {i, n//i}
ans = 0
for div in divisors:
    m = div-1
    if m <= n//div:
        continue
    ans += m
print(ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


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


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


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




N = I()
D = make_divisors(N)
ans = 0
for k in D:
  m =  N//k-1
  if m>k:
    ans += m
print(ans)

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

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

print(ans)

Solution (Python):
N = int(input())
ans = 0
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
for i in make_divisors(N):
    tmp = (N - i) // i
    if tmp == 0:
        continue
    if N // tmp == N % tmp:
        ans += tmp
print(ans)

Solution (Python):
n=int(input())
ans=0
for i in range(1,int(n**0.5)+1):
  if n%i==0 and i<n//i-1:
    ans+=(n//i-1)
print(ans)

Solution (Python):
def diverta19_d():
    N = int(input())
    ans = 0
    for i in range(1, min(N, 10**6+1)):
        d, m = divmod(N-i, i)
        if m == 0 and i < d:
            ans += d
    print(ans)

diverta19_d()

Solution (Python):
import math

n = int(input())
ans = 0
for i in range(1, int(-(-n**0.5//1))+1):
    if n%i == 0:
        m = n//i - 1
        if i < m: ans += m 
print(ans)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7






N = getN()

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

div = make_divisors(N)

num = []
alta = set(div)

for split in div:
    opt = (N // split) - 1
    if opt > 1 and N // opt == N % opt:
        num.append(opt)
print(sum(num))