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

N = int(input())

sqrt_n = int(math.ceil(math.sqrt(N)))

ans = 0
for i in range(1, sqrt_n):
    if N % i == 0:
        target = (N / i) - 1
        if N % target == i:
            ans += target

print(ans)

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


import sys
N = int(input())
ans = 0
if N == 1:
    print(0)
    sys.exit()
    
temp = make_divisors(N)
for i in temp:
    if i == 1:
        continue
    if N // (i-1) == N % (i-1):
        ans += i-1
        
print(ans)

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

def solve():
  n = int(input())
  
  d  = make_divisors(n)
  ans = 0
  for i in d:
    if i-1 <= 1: continue
    else:
      if math.floor(n/(i-1)) == n%(i-1):
        ans += i-1
  print(ans)
solve()

Solution (Python):
N = int(input())
val = []
max_len = [2,4]
def comb(val, max_len, depth=0):
    if depth==len(max_len):
        yield val
        return 

    for i in range(max_len[depth]+1):
        yield from comb(val+[i], max_len, depth+1)





import math
def primeFactor(num):
    prime = {}
    x = 2
    MAX =  math.sqrt(num)+1
    while x <MAX:
        if num%x==0:
            if x in prime:
                prime[x] += 1
            else:
                prime[x]=1
            num //= x
        else:
            x += 1
    if num != 1:
        prime[num]=1
    return prime

divisor = primeFactor(N)


ans = 0
val = []
for it in comb(val, list(divisor.values())):
    total = 1
    for i, j in zip(list(divisor.keys()), it):
    
        total *= i**j

    
    m = total - 1
    if m < 1:
        continue
    if N%m==N//m:

        ans += m
        
print(ans)

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

li = []
m = int(math.sqrt(n))
for i in range(1, m + 1):
    if i + 1 >= n / i:
        break
    if n % i == 0:
        li.append(n // i)

ans = sum(li) - len(li)
print(ans)

Solution (Python):




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

  if n <= 2:
    print(0)
    return

  for i in range(1, n):
    if i * (i + 1) >= n:
      break
    elif n % i != 0:
      continue
    else:
      total += n // i - 1

  print(total)


if __name__ == '__main__':
  main()

Solution (Python):
import math
N = int(input())
n = int(math.sqrt(N))
ans = 0
for i in range(1, n+1):
    if N % i == 0:
        i2 = N//i
        if i2 > i+1:
            ans += i2-1
print(ans)

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


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

    
    return divisors
ans = 0
divisors = make_divisors(n)
for x in divisors:
    tmp = x-1
    if tmp>0 and n//tmp == n%tmp:
        ans += tmp
print(ans)

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

factors = set()
factor = 1
while factor * factor <= n:
    if n % factor == 0:
        factors.add(factor)
        factors.add(n // factor)
    factor += 1

total = 0
for factor in factors:
    k = factor - 1
    if k <= 0:
        continue

    div = n // k
    mod = n % k
    if div == mod:
        total += k

print(total)

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

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

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

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

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

root_n = int(n ** 0.5)

ans = 0
for i in range(1, root_n + 1):
    if n % i == 0:
        a = i
        b = n / i

        m = a - 1
        k = b
        if 0 < k < m:
            ans +=m

        m = b - 1
        k = a
        if 0 < k < m:
            ans += m

print(ans)

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

    return divisors

if __name__ == '__main__':
    N = int(input())
    divs = make_divisors(N)
    ans = 0
    for d in divs:
        if d == 1:
            continue
        if N%(d-1) == int(N/(d-1)):
            ans += d-1

    print(ans)

Solution (Python):
import math
n = int(input())
nn = int(math.sqrt(n))
li = []
count = 0
for i in range(1,nn+1):
    if n % i == 0:
        li.append(i-1)
        li.append(n//i-1)
for i in li:
    if i == 0:
        continue
    if n % i == n // i:
        count += i
print(count)

Solution (Python):
N = int(input())
k = int(1)
ans =  int(0)

while N>k**2 :
    if N%k==0:
        m = int(N/k-1)
        if m>k:
            ans +=m
    k +=1

print(ans)

Solution (Python):
import math
from collections import defaultdict
from itertools import product
from functools import reduce 
from operator import mul


def is_prime(num):
    if not isinstance(num, int):
        return False
    if num <= 1:
        return False
    if num == 2 or num == 3:
        return True
    if num % 6 in [0, 2, 3, 4]:
        return False
    div_max = int(math.sqrt(num))
    for div in range(5, div_max + 1, 2):
        if num % div == 0:
            return False
    return True

def factorint(x):
    factors = defaultdict(int)
    if x==1:
        factors[1] = 1
        return factors
    while not is_prime(x):
        div_max = int(math.sqrt(x))
        for div in range(2, div_max + 1):
            if x % div == 0:
                factors[div] += 1
                x = int(x / div)
                break
    factors[x] += 1
    return factors

ans = 0
n = int(input())
rn = math.sqrt(n+1) + 1
factor_dict = factorint(n)
ks = [range(k+1) for k in factor_dict.values()]
prs = product(*ks)
for pr in prs:
    s = reduce(mul, [factor**p for factor,p in zip(factor_dict.keys(), pr)])
    if s >= rn:
        ans += s -1
print(ans)

Solution (Python):
import math
n=int(input())
sqn=math.sqrt(n)
ch=n-sqn
nums=[]
su=0
stage=2
if n==1:
    print(0)
else:
    while(su<n):
        n_ = math.ceil(n*(stage-1)/stage)
        if n_ == su:
            nums.append(1)
            nums.append(n-su-1)
            break
        nums.append(n_-su)
        su+=n_-su
        if su>=ch:
            nums.append(n-su)
            break
        stage += 1
    ans=[]
    next_div_num = 0
    k=len(nums)
    for i in range(k):
        next_div_num += nums[k-1-i]
        if nums[k-1-i] == 1:
            continue
        sho = n//next_div_num
        d = next_div_num
        if d==0 or sho>d:
            continue
        if sho == n%d:
            ans.append(d)
        elif sho>n%d:
            d-=1
            if d==0 or sho>d:
               continue
            if sho == n%d:
                ans.append(d)
    print(sum(ans))

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

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

Solution (Python):
import math
N = int(input())
ans = 0
x = 1
while 1:
	m = (N-x)//x
	if x >= m:
		break
	if (N-x)%x == 0:
		ans += m
	x += 1
print(ans)

Solution (Python):
import math
N = int(input())
ans = 0
x = 1
tmp = math.ceil(math.sqrt(N))
while 1:
	m = (N-x)//x
	if x >= m:
		break
	if (N-x)%x == 0:
		ans += m
	x += 1
print(ans)

Solution (Python):
import math

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

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

print(ans)

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

print(ans)

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

Solution (Python):
from math import sqrt
n = int(input())
div = []
ans = 0
for i in range(1, int(sqrt(n))+1):
	if n%i == 0 and (n//i) - i > 1:
		ans += (n//i) - 1
print(ans)

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

      
  return divisors
    
N = int(input())
ans = 0
count = make_divisors(N)

for i in count:
  if i != 1:
    q, mod = divmod(N, i-1)
    if q == mod:
      ans += i - 1
print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def prime_factors(n):
    i = 2
    factors = {}
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            if i in factors.keys():
                factors[i] += 1
            else:
                factors[i] = 1
    if n > 1:
        if n in factors.keys():
            factors[n] += 1
        else:
            factors[n] = 1
    return factors

i  = lambda: int(input())

N = i()

pfd = prime_factors(N)

check_num = []

for pf in pfd.keys():
    tmp_num = []
    for i in range(1, pfd[pf] + 1):
        tmp_num.append(pf ** i)
        for n in check_num:
            tmp_num.append(n * (pf ** i))
    check_num += tmp_num

count = 0
for n in check_num:
    if N // (n-1) == N % (n-1):
        count += n-1

print(count)

Solution (Python):


import sys
from math import sqrt

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()





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

m=N
ans=set()
while m>=sqrt(N):
    i=N//m
    j=N%m
    if (i-j)%i==0 and N//m==N//(m-1):
        ans.add(m-1)
    m=N//(i+1)

for m in range(1, int(sqrt(N))+1):
    if N//m==N%m:
        ans.add(m)

print(sum(ans))

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

n = int(input())
ans = 0 
d =div(n) 
for d in d:
    if d != 1:
        q,mod = divmod(n,d-1)

        if q == mod: 
            ans += d - 1 
print(ans)

Solution (Python):
import math

N=int(input())
result=0
if N==1:
    print(0)
else:
    for i in range(1,int(math.sqrt(N))+1):
        if N%i==0:
            if i>1 and N%(i-1)==N//(i-1):
                result+=i-1
            if N%i!=N//i:
                if N%(N//i-1)==N//(N//i-1):
                    result+=N//i-1
    print(result)

Solution (Python):
import math

N = int(input())

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

print(total)

Solution (Python):
from collections import deque
n=int(input())
yaku=deque([])
for i in range(1,int(n**0.5)+1):
    if n%i==0:
        yaku.append(i)
        yaku.append(n//i)
yaku=list(sorted(set(yaku)))[1:]
ans=0
for i in yaku:
    if n//(i-1)==n%(i-1):
        ans+=i-1
print(ans)

Solution (Python):

import time

def solve_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_favorite_nums(N, divisors):
  favorite_num_list = []
  for divisor in divisors:
    m = N // divisor - 1
    if (m == 1 or m == 0):
      pass
    elif (N % m == N // m):
      favorite_num_list.append(m)
  return favorite_num_list



if __name__ == '__main__':
  start = time.time()

  N = int(input())
  divisors = solve_divisors(N)
  favorite_nums = solve_favorite_nums(N, divisors)
  print(sum(favorite_nums))

  elapsed_time = time.time() - start

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

if n < 100000:

    ans = 0
    x = 1

    while x < n:
        if n % x == 0:
            m = n // x - 1
            if m <= x:
                break
            else:
                ans += m
        x += 1

    print(ans)

    exit()


ans = 0
x = 1

t = int(n ** 0.5)

while x <= int(n ** 0.5):
    if n % x == 0:
        ans += n // x - 1
    x += 1

if t * t == n:
    ans -= t - 1

print(ans)

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

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

    divisors.sort()
    return divisors

div = make_divisors(N)


min_m = 0
if len(div)%2 == 1:
    min_m = int((len(div)+1)/2)
if len(div)%2 == 0:
    min_m = int(len(div)/2)
    if div[min_m] - div[min_m-1] < 2:
        min_m += 1

print(sum(div[min_m:])-(len(div)-min_m))

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

div = make_divisors(N)


min_m = 0
if len(div)%2 == 1:
    min_m = int((len(div)+1)/2)
if len(div)%2 == 0:
    min_m = int(len(div)/2)
    if div[min_m] - div[min_m-1] < 2:
        min_m += 1

print(sum(div[min_m:])-(len(div)-min_m))

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


n = int(input())
n_divisor = all_divisor(n)
ans = 0
for i in n_divisor:
  mini_ans = (n - i) // i
  if i >= mini_ans:
    break
  ans += mini_ans 
print(ans)

Solution (Python):
import math

def all_divisor(n):
  small = [1]
  large = [n]
  for i in range(2, int(math.sqrt(n))+1):
    if n % i == 0:
      small.append(i)
      large.append(n//i)
  large.reverse()
  divisor = small + large
  return divisor


n = int(input())
n_divisor = all_divisor(n)
ans = 0
for i in n_divisor:
  mini_ans = (n - i) // i
  if i >= mini_ans:
    break
  ans += mini_ans 
print(ans)

Solution (Python):
from math import floor, sqrt


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


def divisor(N):
    divs = []
    sup = floor(sqrt(N))
    for i in range(1, sup+1):
        if N % i == 0:
            divs.append(i)
            divs.append(N // i)
    return sorted(divs)


if __name__ == '__main__':
    main()

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:
            left.append(p)
            right.append(n//p)
    res = left + right[::-1]
    return res
        
N = int(input())

div = divisor(N)
ans = 0

for d in div:
    if d != 1 and N // (d-1) == N % (d-1):
        ans += (d-1)

print(ans)

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

Solution (Python):
import math
n,a=int(input()),0
if n<3:print(0);exit()
for i in range(1,int(math.sqrt(n))+1):
  if n%i==0:
    m=n//i-1
    if n//m==n%m:a+=n//i-1
print(a)

Solution (Python):
import math

N = int(input())

ans = 0

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

Solution (Python):
import numpy as np
N = int(input())
ans = 0 if N<3 else N-1
num = np.arange(2, max(2, np.sqrt(N)), dtype=int)
num = np.concatenate([num, np.array(N/num[N%num==0], dtype=int)])
mask = N%(num-1) == N//(num-1)
ans += int(np.sum(num[mask])-np.sum(mask))
print(ans)

Solution (Python):
import numpy as np
N = int(input())
if N==1 or N==2:
    print(0)
elif N==3:
    print(2)
else:
    ans = N-1
    num = np.arange(2, np.sqrt(N), dtype=int)
    mask = (N%num==0)
    check = np.array(N/num[mask], dtype=int)
    num = np.concatenate([num, check])
    mask2 = N%(num-1) == N//(num-1)
    ans += int(np.sum(num[mask2])-np.sum(mask2))
    print(ans)

Solution (Python):
def searchDivisors(n):
    lstDivisors = []
    t = int(n ** .5)
    for a in range(1, t + 1):
        if n % a == 0:
            lstDivisors.append(a)
            b = n // a
            if b != a:
                lstDivisors.append(b)
    lstDivisors.sort()

    return lstDivisors


N = int(input())
ans = 0
lstDivisors = searchDivisors(N)



for i in lstDivisors:
    if i == 1:
        continue
    m = i - 1
    if N // m == N % m:
        ans += m


print(ans)

Solution (Python):
def searchDivisors(n):
    lstDivisors = []
    t = int(n ** .5)
    for a in range(1, t + 1):
        if n % a == 0:
            lstDivisors.append(a)
            b = n // a
            if b != a:
                lstDivisors.append(b)
    lstDivisors.sort()

    return lstDivisors


N = int(input())
ans = 0
lstDivisors = searchDivisors(N)


for i in lstDivisors:
    if i == 1:
        continue
    i -= 1
    if N // i == N % i:
        ans += i


print(ans)

Solution (Python):
def searchDivisors(n):
    lstDivisors = []
    t = int(n ** .5)
    for a in range(1, t + 1):
        if n % a == 0:
            lstDivisors.append(a)
            b = n // a
            if b != a:
                lstDivisors.append(b)
    lstDivisors.sort()

    return lstDivisors


N = int(input())
ans = 0
lstDivisors = searchDivisors(N)


for k in lstDivisors:
    m = N // k - 1
    if k == m:
        continue
    if k > m:
        break
    ans += m


print(ans)

Solution (Python):
def searchDivisors(n):
    lstDivisors = []
    t = int(n ** .5)
    for a in range(1, t + 1):
        if n % a == 0:
            lstDivisors.append(a)
            b = n // a
            if b != a:
                lstDivisors.append(b)
    lstDivisors.sort()

    return lstDivisors


N = int(input())
ans = 0
lstDivisors = searchDivisors(N)


for k in lstDivisors:
    m = N // k - 1
    if k == m:
        continue
    if k > m:
        break
    ans += m


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

    
    return divisors

yakusuli = make_divisors(n)

ans = 0

for i in yakusuli:
    if i < n // i - 1:
        ans += n // i - 1

print(ans)

Solution (Python):
from math import ceil,floor,sqrt
import sys
N=int(input())
ans=0

def f(x):
    if x==0:
        return False
    else:
       return (N//x)==N%x
if N<=10000:
    for i in range(1,N+1):
        if f(i):
            ans+=i
    print(ans)
    sys.exit()
for i in range(1,int(sqrt(N))+5):
    if N%i==0:
        t = N // i
        if f(i-1):
            ans+=(i-1)
        if f(t-1):
            ans+=(t-1)
print(ans)

Solution (Python):
def d_divrem_number(N):
    """
    与えられた正整数Nに対して、以下の条件を満たす正整数mの総和を求めよ。
    ・Nをmで割った商と余りが等しい。
    """

    
    
    

    def divisor_list(n):
        """n の正の約数のリスト"""
        ret = []
        for k in range(1, int(n**0.5) + 1):
            if n % k == 0:
                ret.append(k)
                if k != n // k:
                    ret.append(n // k)
        ret.sort()
        return ret

    candidates = list(map(lambda x: x - 1, reversed(divisor_list(N))))
    return sum(m for m in candidates if m != 0 and N // m == N % m)

N = int(input())
print(d_divrem_number(N))

Solution (Python):
N = int(input())
U = int(N**(1/2))
cnt = 0
for i in range(1, U+2):
    if N%i==0 and N//i-1>i:
        cnt += (N//i)-1
if N==2:
    print(0)
else:
    print(cnt)

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

divisor_lst = []
i = 1
while i+2 <= N//i:
    if N % i == 0:
        divisor_lst.append(N//i)
    i += 1    

arr = np.array(divisor_lst)
arr -= 1
print(int(np.sum(arr)))

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

for x in make_divisors(n):
    if x > 2 and n//(x-1) == n%(x-1):
        ans += x-1
print(ans)

Solution (Python):
from math import sqrt
from collections import defaultdict
N = int(input())
divisors = []
ans = 0

for i in range(1, int(sqrt(N))+1):
    if N % i == 0:

        if i ** 2 != N:
            divisors.append(i)
            divisors.append(int(N/i))

        else:
            divisors.append(i)

for div in divisors[1:]:
    d = int(N//(div-1))
    
    if d == N - d * (div-1):
        ans += div-1
        
print(ans)

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

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


ds = make_divisors(N)
ans = list()

for d in ds:
    if d < 2:
        continue
    a = d - 1
    if (N // a) == (N % a):
        ans.append(a)

print(sum(ans))

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

    
    return divisors
  
ans=0
for i in make_divisors(n):
  if i-1>0:
    if n//(i-1)==n%(i-1):
      ans+=i-1

print(ans)

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

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

s = make_divisors(n)
sum = 0

for i in s:
    if i > 1:
        if n // (i - 1) == n % (i - 1):
            sum += i - 1

print(sum)

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

if(N==1):
    print(0)
else:
    res = make_divisors(N)

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

st = set()
for d in range(1, int(pow(N, 0.5)) + 1):
    if N % d == 0:
        st.add(d)
        st.add(N // d)









ans = 0
for dd in st:
    dd -= 1
    if dd == 0: continue
    q, r = divmod(N, dd)
    if q == r:
        ans += dd
print(ans)

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

    
    return divisors

n = int(input())
div  = make_divisors(n)

l = []
for i in div:
    var = i - 1
    if var != 0 :
        if n//var == n%var:
            l.append(var)

print(sum(l))

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

N = int(input())



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


print(ans)

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

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


for n in range(1, int(N ** 0.5) + 1):
    if N % n == 0:
        div.append(n)
        div.append(N // n)
        
ans = 0


for d in div:
    if d - 1 <= 0:
        continue
    if N // (d - 1) != (N % (d - 1)):
        continue
        
 

    ans += (d - 1)
    
print(ans)

Solution (Python):

"""
Created on Sun May 12 13:16:22 2019

@author: Yamazaki Kenichi
"""
import math

N = int(input())
a = int(math.ceil(pow(N, 1/2)))
ans = 0
for i in range(1,a):
    if N % i == 0 and (N // i - 1) != i:
        ans += (N - i) // i        
print(ans)

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

n = int(input())

yaku = make_divisors(n)

ans = 0
for y in yaku:
    m = y - 1
    if m and (n//m == n % m):
        ans += m
print(ans)

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

for a in range(1, int(sqrt(N))+1):
    if N % a == 0:
        m = N // a - 1
        if m > a:
            ans += m

print(ans)

Solution (Python):
def sample_code(N):

 
    fct = factorize(N)
 

 
    for div in divisorize(fct):
        b = num(div)


def divisorize(fct):
    b,e = fct.pop()
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b,k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]

def factorize(N):
    fct = []
    b,e = 2, 0
    while b * b <= N:
        while N % b == 0:
            N = N // b
            e = e + 1
        if e > 0:
            fct.append((b,e))
        b,e = b + 1,0
    if N > 1:
        fct.append((N,1))
    return fct

def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base ** exponent
        divisor_list.append(a)
    return a

N = int(input())
sum_m = 0
divisor_list = []
if N == 1:
    print(0)
else:
    sample_code(N)
    divisor_list = list(set(divisor_list))

    for c in divisor_list:
        if c != 1 and c!= 2:
            if N // (c-1) >= (c-1):
                continue
            else:
                sum_m += c - 1

    print(sum_m)

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

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

print(ans)

Solution (Python):



def main():
    N = int(input())
    ans = 0
    divisors = make_divisors(N)
    for d in divisors:
        m = d - 1
        if m > 0 and N % m == N//m:
            ans += m
    print(ans)
    return


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

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

l = yakusu(n)

ans = 0
for m in l:
    if m-1 > 0 and n == int(n/(m-1))*m:
        ans += m-1
    

print(ans)

Solution (Python):
from math import sqrt, floor
n = int(input())
ans = 0
for i in range(1, floor(sqrt(n))+1):
    if n % i == 0:
        if n / i < i - 1:
            ans += i - 1
        if i < n / i - 1:
            ans += n // i - 1
print(ans)

Solution (Python):
n = int(input())
s = 0
m = 1
while m * m <= n:
    if n % m == 0:
        num1 = m - 1
        if num1 and n // num1 == n % num1:
            s += num1
        num2 = n // m - 1
        if num1 != num2 and num2 and n // num2 == n % num2:
            s += num2
    m += 1
print(s)

Solution (Python):
import math

N = int(input())

cs = set()
for m in range(1, int(math.sqrt(N))+1):
    q, r = divmod(N, m)
    if r != 0:
        continue
    cs.add(q-1)
    cs.add(m-1)

s = sum(c if N // c == N % c else 0 for c in cs if c > 0)
print(s)

Solution (Python):
import math

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

def solve(N):
    result = 0
    ms = [] 
    for m in range(1, N):
        d, r = divmod(N, m)
        if d == r:
            result += m
            ms.append(m)

    return result, ms

def solve1(N):
    s = 0
    ms = [] 
    for m in range(1, int(math.sqrt(N)+1)):
        d, r = divmod(N, m)
        if r == 0:
            if d < m-1:
                s += m - 1
                ms.append(m-1)
            else:
                s += d - 1
                ms.append(d-1)
    return s, ms

s = 0
cs = set()
for m in range(1, int(math.sqrt(N)+1)):
    q, r = divmod(N, m)
    if r != 0:
        continue
    cs.add(q-1)
    cs.add(m-1)

def check(c):
    if c == 0:
        return 0
    return c if N // c == N % c else 0
        
s = sum(check(c) for c in cs)
print(s)

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

Solution (Python):
import math

N = int(input())
ans = 0
for i in range(1, math.ceil(math.sqrt(N)) + 1):
    if N % i:
        continue
    n = N // i - 1
    if n and N % n == N // n:
        ans += n
print(ans)

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

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

print(ans)