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
input = sys.stdin.readline



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():
    N = int(input())
    D = make_divisors(N)
    ans = 0
    for a in D:
        if a == 1:
            continue
        d, m = divmod(N, a-1)
        if d == m:
            ans += a-1
    print(ans)


if __name__ == '__main__':
    main()

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



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():
    N = int(input())
    D = make_divisors(N)
    ans = 0
    for a in D:
        m = N//a - 1
        if m > a:
            ans += m
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
cnt = 0
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        q = N//i
        m = i-1
        if q<m:
            cnt += m
        m = N//i-1
        q = i
        if q<m:
            cnt += m
print(cnt)

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

    
    return divisors

ans = 0
for i in make_divisors(N):
    if i != 1:
      if N//(i-1) == N % (i-1):
          ans += (i-1)
print(ans)

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

N = ni()
answer = 0
cur = 1
while cur * (cur + 2) <= N:
    y = N - cur
    if y % cur != 0:
        cur += 1
        continue
    x = y // cur
    if x > cur:
        
        answer += x
    cur += 1
print(answer)

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

Solution (Python):


n=int(input())

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

print(ans)

Solution (Python):
N = int(input())
ans = 0
d = 1
while d * d < N:
  if N % d == 0:
    m = (N // d) - 1
    if d < m:
    	ans += m
  d += 1
print(ans)

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

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

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

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

ans = 0

now = 1

while now ** 2 <= N:

    if N % now == 0 and (N // now - 1) > 0 and N // (N // now - 1) == N % (N // now - 1):

        ans += N // now - 1

    now += 1

print (ans)

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

print(ans)

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

N=int(readline())

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)


answer=0
for i in range(len(div)):
  d=div[i]-1
  if d!=0 and N//d==N%d:
    answer+=d
print(answer)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
if n == 1:
    print(0)
    quit()
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(reverse=True)
    return divisors
m = make_divisors(n)
res = m[:len(m)//2]
if n //(res[-1]-1) != n % (res[-1]-1):
    res[-1] = 1
print(sum(res) - 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())
md = make_divisors(N)



ans = 0
for i in md:
  m = N // i - 1
  if m != 0 and N // m < m:
    ans += m

print(ans)

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

for i in range(1, int(n**0.5) + 1):
    x = (n - i) // i
    
    if i * x + i == n:
        if i != x and i**2 != n:
            cnt += x

print(cnt)

Solution (Python):
from math import floor


def divisor(n):
    left = [1]
    right = [n]
    sup = floor(pow(n,1/2))
    for p in range(2,sup+1):
        if n % p == 0:
            if p == n//p:
                left.append(p)
                continue
            left.append(p)
            right.append(n//p)
    res = left + right[::-1]
    return res


N = int(input())
res = divisor(N)
ans = 0
for d in res:
    m = d - 1
    if m == 0:
        continue
    if N % m == N // m:
        ans += m

print(ans)

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

x=n**0.5

if x-x//1!=0:
    x=int(x//1)
else:
    x=int(x//1)-1
y=0

for i in range(1,x+1):
    if (n-i)/i-(n-i)//i==0:
        if int((n-i)//i)!=i:
            y+=int((n-i)//i)

print(y)

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

d0=N
i=1
ans=[]
while True:
    if (N-i)//i<=i:break
    if (N-i)%i==0:
        ans.append((N-i)//i)
    i+=1
print(sum(ans))

Solution (Python):





mod=10**9+7
def factorial(x): 
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): 
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): 
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    
    
    
    
    
    
    
    
    
    
    n=int(input())
    if n==2:
        print(0)
        return
    ans=0
    for i in range(int(n**(1/2))+3):
        i+=1
        if (n-i)%i == 0 and i < (n-i)//i:
            if i==n**(1/2):
                break
            ans+=(n-i)//i
    print(ans)
main()

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

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

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

na=[]
for i in range(1,int(N**0.5)+1):
  if N%i==0:
    if i<N//i-1:
      na.append(N//i-1)


print(sum(na))

Solution (Python):
n=int(input())
def pri(n):
  l=[]
  for i in range(1,int((n)**(1/2))+1):
    if n%i==0:
      l.append(i)
      if i!=n//i:
        l.append(n//i)
  return l
list1=pri(n)
sum=0
for i in list1:
  if n>i*(i+1):
    sum+=n//i-1
print(sum)

Solution (Python):
n=int(input())
c=0
for i in range(1,int(n**.5)+1):
  if n%i==0:
    if n//i-i>1:
      c+=n//i-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)

    divisors.sort()
    return divisors

n = int(input())


ans = 0
for i in make_divisors(n):
    if i >= n ** 0.5 + 1:
        ans += i-1

print(ans)

Solution (Python):
import math
n=int(input())
lim=int(math.sqrt(n))
cnt=0
if lim**2==n:
    for i in range(1,lim):
        if n%i==0:
            cnt+=n//i-1
    print(cnt)
else:
    for i in range(1,lim+1):
        if n%i==0:
            cnt+=n//i-1
        a=int(math.sqrt(n))
    if a*(a+1)==n:
        cnt-=a 
    print(cnt)

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



def solve(n):
    ans = 0
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            if n//i > i+1:
                ans += n//i-1
    return ans

N = I()
print(solve(N))

Solution (Python):

from math import sqrt


def divisors(n: int) -> set:
    
    divs = set()
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0:
            divs.add(i)
            divs.add(n // i)
    return divs


def main():
    N = int(input())
    divs = divisors(N)
    ans = 0
    for m in divs:
        if m == 1:
            continue
        m -= 1
        if N // m == N % m:
            ans += m
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

def divisors(n: int) -> set:
    
    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


def main():
    N = int(input())
    divs = divisors(N)
    ans = 0
    for m in divs:
        if m == 1:
            continue
        m -= 1
        if N // m == N % m:
            ans += m
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):


def divisors(n: int) -> set:
    """
    Compute divisors of a number.
    
    Args: n (int): an integer to be evaluated.
    Returns: div (set): set of divisors
    """
    div = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            div.add(i)
            div.add(n // i)
    return div


def main():
    N = int(input())
    divs = divisors(N)
    divs.discard(1)
    ans = 0
    for m in divs:
        m -= 1
        if N // m == N % m:
            ans += m
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

n = I()
lst = make_divisors(n)
ans = 0
for i in lst:
    if i == 1:
        continue
    a,b = divmod(n,i-1)
    if a == b:
        ans += i-1
print(ans)

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

divs = []
for i in range(1,int(N**0.5)+2):
  if N % i == 0:
    if i < N//i -1:
      divs.append(N//i-1)
    else:
      break
print(sum(divs))

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

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

Solution (Python):
N = int(input())
ds = set()
for d in range(1, N+1):
  if d*d > N:
    break
  if N%d == 0:
    ds.add(d)
    ds.add(N//d)
r = 0
for d in ds:
  m = d-1
  if m == 0:
    continue
  if N%m == N//m:
    r += m
print(r)

Solution (Python):

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

Solution (Python):

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

Solution (Python):
n = int(input())
ans = 0
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        x, m = min(i, n // i), max(i, n // i) - 1
        if m > x:
            ans += m
print(ans)

Solution (Python):
def get_divisor(n):
    a,b = [],[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            a.append(i)
            b.append(n//i)
    if a[-1]==b[-1]:b.pop()
    a.extend(b[::-1])
    return a

N = int(input())
ans = 0
for m in get_divisor(N):
    m-=1
    if m==0 : continue
    if N//m == N%m: ans+=m
print(ans)

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

for i in range(len(divisors)):
    if m[i]- divisors[i] < 2:
        m[i] = 1 


print(sum(m)-len(m))

Solution (Python):

import sys

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 solve(N: int):
    divisors =  make_divisors(N)
    res = 0
    for i in divisors:
        t = i-1
        if t > 0 and N // t == N % t:
            res += t
    print(res)



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

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n = I()

    return


def B():
    n = I()

    return


def C():
    n = I()

    return


def D():
    def factorize(n):
        if n < 4:
            return [1,n]
        res = []
        for i in range(1,int(n**0.5)+1):
            if n%i == 0:
                res.append(i)
                if n//i != i:
                    res.append(n//i)
        res.sort()
        return res
    n = I()
    if n <= 2:
        print(0)
        quit()
    f = factorize(n)
    ans = 0
    for i in f:
        m = max(0,n//i-1)
        if i<m:
            ans += m
    print(ans)
    return


def E():
    n = I()

    return


def F():
    n = I()

    return


def G():
    n = I()

    return


def H():
    n = I()

    return


def I_():
    n = I()

    return


def J():
    n = I()

    return


if __name__ == "__main__":
    D()

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

import math
Nq = int(math.sqrt(N+1))


so = 0
for i in range(1,Nq+1):
  if (N%i != 0):
    continue
  if (N//i < i):
    continue
  
  m,r = (N//i)-1,i
  if ( r<m ):
    so += m
  
  m,r = i-1,(N//i)
  if (N//i != i):
    if (r<m):
      so += m

print ( so)

Solution (Python):
N = int(input())
ans = 0
if N >= 2:
    p = 1
    while p*p <= N:
        q, r = divmod(N, p)
        if r == 0 and p < q - 1:
            ans += q - 1
        p += 1
print(ans)

Solution (Python):
from collections import defaultdict

def prime_factorization(n):
    '''
    Trial division.
    Input: 
        n : a positive integer
    Output:
        a dictionary of 
    '''
    result = defaultdict(int)
    if n < 2:
        return result
    while n % 2 == 0:
        result[2] += 1
        n //= 2
    p = 3
    while p*p <= n:
        while n % p == 0:
            n //= p
            result[p] += 1
        p += 2
    if n > 1:
        result[n] += 1
    return result

N = int(input())
ans = 0
if N >= 2:
    p = 1
    while p*p <= N:
        q, r = divmod(N, p)
        if r == 0 and p < q - 1:
            ans += q - 1
        p += 1
print(ans)

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

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

Solution (Python):
import sys

N = int(input())
sum = 0

for i in range(1, N+1):
    if (N-i) % i == 0:
        m = int((N-i) / i)
        if(m <= i):
            print(sum)
            sys.exit()
        
        sum += m
    if((N-i)/i < i):
        print(sum)
        sys.exit()

Solution (Python):
n = int(input())
a = []
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        a.append(i - 1)
        if i != n // i:
            a.append(n // i - 1)
ans = 0
for i in a:
    if i and n // i == n % i:
        ans += i
print(ans)

Solution (Python):
import math
N = int(input())
num = 0
i = 1
while i <= math.sqrt(N):
    if N % i == 0:
        a = i - 1
        b = (N // i) - 1
        if a == b:
            if a > 0 and N // a == N % a:
                num += a
        else:
            if a > 0 and N // a == N % a:
                num += a
            if b > 0 and N // b == N % b:
                num += b
    i += 1

print(num)

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

for i in range(1, int(N**0.5)+1):
    if not N % i:
        n = N // i
        if i == n:
            nums.append(i-1)
        else:
            nums.extend([i-1, n-1])

print(sum([n for n in nums[1:] if N // n == N % n]))

Solution (Python):
n = int(input())
l = int(-(-(n ** (1/2)) // 1))
total = 0
for i in range(1, l):
	if n % i == 0 and n != i * (i+1):
		total += (n - i) // i
print(int(total))

Solution (Python):
N = int(input())
ans = 0
for x in range(1, int(N**.5)+1):
    if N % x == 0:
        y = N//x
        if x == y:
            if y < x-1:
                ans += x-1
        else:
            if y < x-1:
                ans += x-1
            if x < y-1:
                ans += y-1
print(ans)

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
	
def main():
	N = int(input())
	
	tmp = make_divisors(N)
	ans = []
	
	for i in tmp:
		a = i - 1
		if a == 0:
			continue
		if N // a == N % a:
			ans.append(a)
	
	print(sum(ans))
	
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__":
	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
fav = make_divisors(n)
result = 0
for x in fav:
    if x == n:
        continue
    m = int(n/x)-1
    if int(n/m)==n%m:
        result += m
print(result)

Solution (Python):
import math
ans=0
m=[]
N=int(input())
rN=math.floor(math.sqrt(N))
for i in range(1,rN+1):
    if N%i==0:
        m.append(i)
        m.append(int(N/i))
    else:
        pass
m.sort()
m2=list(map(lambda x: x-1,m))
for i in m2:
    if i==0:
        pass
    else:
        a,b=divmod(N,i)
        if a==b:
            ans+=i
        else:
            pass
print(ans)

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

N = int(input())
a = make_divisor(N)

sum = 0
for i in a:
    if N // i - 1 > i:
        sum += (N // i) - 1

print(sum)

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
ans = 0
divisors = make_divisors(N)

for d in divisors:
    m = (d - 1)
    if m and (N//m == N % m):
        ans += m
print(ans)

Solution (Python):

"""
D - DivRem Number
https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d

"""
import sys


def solve(N):
    def divisor(N):
        divisors = set()
        for i in range(1, int(N**0.5)+1):
            if N % i == 0:
                divisors.add(i)
                divisors.add(N // i)
        return divisors

    ans = 0
    for q in divisor(N):
        if q == 1:
            continue
        a, b = divmod(N, q-1)
        if a == b:
            ans += (q-1)
    return ans


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

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

ans = 0

for i in range(1,10**6+1):
    if i*i >= n:
        break
    if n % i != 0:
        continue
    
    m = (n // i) - 1
    if i < m:
        ans += m

print(ans)

Solution (Python):
n = int(input())
if n == 1:
  print(0)
  quit()
else:
  res = n-1 if n%(n-1) == int(n/(n-1)) else 0
i = 2
while i*i <= n:
  if n%i == 0:
    if n%(i-1) == int(n/(i-1)):
      res += i-1
    if i*i != n:
      if n%(int(n/i)-1) == int(n/(int(n/i)-1)):
        res += int(n/i) - 1
  else:
    pass
  i += 1
print(res)

Solution (Python):
from math import sqrt
def main():
    n = int(input().rstrip())
    sqrt_n = int(sqrt(n))

    total = 0
    for number in range(1,sqrt_n + 1):
        if n % number > 0:
            continue
        remain = n - number
        x, y = divmod(remain, number)
        
        if y == 0 and x > number:
            
            total += x
        
        

    print(total)

if __name__ == "__main__":
  main()

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

N = int(input())

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


primes = prime_decomposition(N)


counter = Counter(primes)
values = [[k**i for i in range(v+1)] for k, v in counter.items()]
p = product(*values)


divisors = []
for v in p:
    div = 1
    for w in v:
        div *= w
    divisors.append(div)


ans = 0
for i in divisors:
    j = N / i
    if (i > j + 1) & (i >= 1) & (j >= 1):
        ans += i - 1
print(ans)

Solution (Python):
N = int(input())
tmp = N ** 0.5
sum = 0
k =1
while k < tmp:
    m = N // k -1 
    if N % k == 0 and m > tmp-1 and k < m: 
        sum += m
    k += 1
print(sum)

Solution (Python):
import math

N = int(input())

result = 0
D = math.ceil(math.sqrt(N))
for i in range(1, D):
  if N % i == 0:
    m = N // i - 1
    if N % m != 0:
      result += m

print(result)

Solution (Python):
import numpy as np

N = int(input())

ans = 0
for i in range(1, int(np.sqrt(N)) + 1):
    if N % i != 0:
        continue
    m = N//i - 1
    if m <= i:
        continue
    if N % m == 0:
        continue
    ans += m
print(ans)

Solution (Python):


import sys
import copy

sys.setrecursionlimit(1000000)






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

    ret.sort()
    return ret


N = int(input())
divisors = DIVISORS(N)

ans = 0
for x in divisors:
    m = x - 1
    if m == 0:
        continue
    r = N % m
    if r == N // m:
        ans += m

print(ans)

Solution (Python):
read = input
from math import sqrt
N = int(read())
sqrt_n = int(sqrt(N))
k = 1

ans = 0
m = 0

while k <= sqrt_n + 1000:
    if N % (k) == 0:
        m = N // (k)

        if not m-1 > k:break
        ans += m - 1
    k += 1
print(ans)

Solution (Python):
import sys

N = int(sys.stdin.readline())
i = 1
s = 0

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

Solution (Python):
N = int(input())
total = 0
for q in range(1,N // int(N**0.5) + 1):
	try:
		if N % (N // q - 1) == N // (N // q - 1):
			total += (N // q) - 1
	except:
		pass
print(total)

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

if n > 2:
  ans += n-1

for i in range(2,math.ceil(n**0.5)+1):
  if n % i == 0:
    j = n // i
    if n % (i-1) == n // (i-1):
      ans += i-1
    if i != j > 1 and n % (j-1) == n // (j-1) :
      ans += j-1
  
print(ans)

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

Solution (Python):
import math as m


n = int(input())
ans = 0
for i in range(1,m.ceil(m.sqrt(n))):
    if n%i==0:
        if n//i == i+1 : break
        ans += n//i -1

if n in [1,2]: ans = 0

print(ans)

Solution (Python):



def main():
    n = int(input())
    ans = 0

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

            if n // m == n % m:
                ans += m

    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
from sys import exit

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


ans_list = make_divisors(N)

ans = []

for ans_l in ans_list:
	a = ans_l - 1
	if a == 0:
		continue
	if N // a == N % a:
		ans.append(a)

print(sum(ans))

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

root = math.ceil(math.sqrt(N))
for i in range(root):
    if N % (i + 1) == 0 and (i + 1) + 1 < N // (i + 1):
        result += N // (i + 1) - 1

print(result)

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

divisors = make_divisors(N)

ans = 0
for divisor in divisors:
	if divisor != 1:
		shou = N // (divisor-1)
		amari = N % (divisor-1)
		if shou == amari and divisor-1 > amari:
				ans += divisor-1

print(ans)

Solution (Python):
import math
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
q = int(math.sqrt(n))+1
sum = 0
for i in range(1,q):
    ddprint("i {}".format(i))
    if n%i==0:
        m = n//i - 1
        ddprint("divides m {}".format(m))
        if m==0:
            continue
        if n%m == n//m:
            sum += m
print(sum)

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

ans = 0
prefnum = []

for div in range(1, sqrtN+1):
  if( N % div == 0):
    quot = int(N/div)
    if((quot-1) > div):
      prefnum.append(int(quot-1))
      
for i in prefnum:
  ans = ans + i

print(ans)

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

Solution (Python):
n = input()

ans = 0
for d in xrange(1, int(n ** 0.5) + 1):
    if n % d == 0:
        m = n // d - 1
        if m * m > n: ans += m

print ans

Solution (Python):


"""解説
http://drken1215.hatenablog.com/entry/2019/05/12/004500

N//m = N%m = k （kは約数。かつ余り）とすると、

N = mk + k
N = k(m+1)

k は MOD m の余りなので、m > k である。
よって、

N = k*(m+1) > k*k

よって、

N > k**2
√N > k

これに気づけばOK。あとはkについて全探索。O(√N)


(例)
・N=8, m=3のとき
3*2 + 2 = 8
m*k + k = N

・N=8, m=7のとき
7*1 + 1 = 8
m*k + k = N

"""
import math

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

    ans = 0
    for k in range(1, math.floor(math.sqrt(N))+1):
        if N%k != 0: continue 
        
        
        m = (N/k) - 1
        if m <= 0: continue
        if N//m == N%m:
            ans += m
    print(int(ans))


if __name__ == "__main__":
    solve()

Solution (Python):


"""解説
http://drken1215.hatenablog.com/entry/2019/05/12/004500

N//m = N%m = k （kは約数。かつ余り）とすると、

N = mk + k ...(1)
N = k(m+1)

k は MOD m の余りなので、m > k である。
よって、

N = k*(m+1) > k*k

よって、

N > k**2
√N > k

これに気づけばOK。あとはkについて全探索。O(√N)


(例)
・N=8, m=3のとき
3*2 + 2 = 8
m*k + k = N

・N=8, m=7のとき
7*1 + 1 = 8
m*k + k = N

"""
import math

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

    ans = 0
    for k in range(1, math.floor(math.sqrt(N))+1):
        if N%k != 0: continue 
        
        
        m = (N/k) - 1
        if m <= 0: continue
        if N//m == N%m:
            ans += m
    print(int(ans))


if __name__ == "__main__":
    solve()

Solution (Python):
n = int(input())
  
flag = True
a = 1
m = 0
while flag:
        if n-a <= a**2:
                flag = False
        else:
                if (n-a) % a == 0:
                        m += (n-a) // a
        a += 1

print(m)

Solution (Python):
import math
ans=0
n=int(input())
yakusu=[]
for num in range(1,math.floor(math.sqrt(n))+1):
    if n%num==0:
        yakusu.append(num)
        if n//num>num:
            yakusu.append(n//num)

for k in yakusu:
    m=n//k-1
    if m>k:
        ans+=m
print(ans)

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

sq = int((N+1)**0.5)

s = 0
for i in xrange(1, sq):
    if N % i == 0:
        s += (N/i) - 1
        
print s

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

n = int(input())
A = divisor(n)
ans = 0
for a in A:
    i,j = divmod(n,a-1)
    if i == j:
        ans += a-1
print(ans)