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

div = []
i = 1
while i * i <= N:
    if N % i == 0:
        div.append(i)
    if N // i != i:
        div.append(N // i)
    i += 1
div.sort()
prev = 0
ans = 0
for d in div:
    m = N // d - 1
    if m > 0 and N // m == N % m:
        ans += m

print(ans)

Solution (Python):


import math


def solve(n):
    res = 0
    for q in range(1, math.floor(math.sqrt(n)) + 1):
        m1, mo = divmod(n, q)
        if mo != 0 or m1 - q < 2:
            continue
        res += m1 - 1
    return res


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


if __name__ == "__main__":
    main()

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



ans = 0
for x in range(1,N+1):
  if x*(x+2) > N:
    break
  m,r = divmod(N,x)
  if r != 0:
    continue
  ans += m - 1

print(ans)

Solution (Python):
import sys
range = xrange
input = raw_input

N = int(input())

div = 0
i = 1
while i*i<N:
    if N%i==0:
        m = i-1 
        if m and (m+1)*(N//m) == N: 
            div += m

        m = (N//i)-1 
        if m and (m+1)*(N//m) == N: 
            div += m
    i += 1

if i*i==N:
    m = i-1 
    if m and (m+1)*(N//m) == N: 
        div += m

print div

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


N = int(input())
s = make_divisors(N)

ans = 0
for ss in s:
    ss -= 1
    if ss <= 1: continue
    k, r = divmod(N, ss)
    if r == 0: continue
    if k >= ss: continue
    ans += ss
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

yakusuu_list = make_divisors(N)

cnt = 0
for yaku in yakusuu_list[::-1]:
    m = yaku-1
    a = N / yaku
    if a >= m:
        break
    else:
        cnt += m

print(cnt)

Solution (Python):
N = int(input())
def divisor_all(n): 
    import math as ma
    l = [1,n]
    for i in range(2,int(ma.sqrt(n))+1):
        if n % i == 0:
            l.append(i)
            l.append(n//i)
    l.sort()
    return l 
ll = divisor_all(N)
ans = 0
for i in range(len(ll)):
    r = ll[i]
    m = N//r-1
    if r<m:
        ans += m

print(ans)

Solution (Python):

import sys


def solve(N: int):
    res = 0
    x = 1
    while x * x <= N:
        mp1, r = divmod(N, x)
        m = mp1 - 1
        if x >= m:
            break
        x += 1
        if r > 0:
            continue
        res += m
    print(res)
    return



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

if __name__ == '__main__':
    main()

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

Solution (Python):
n = int(input())
i = 1
ans = 0
while True:
    d, m = divmod(n, i)
    d -= 1
    if i >= d:
        break
    if m != 0:
        i += 1
        continue
    ans += d
    i += 1
print(ans)

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

root_n = int(n ** 0.5)

ans = 0

for i in range(1, root_n + 1):
    if n % i == 0 and i < n // i - 1:
        ans += n // i - 1

print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq as hq
import itertools as its
import operator as op



inf = float('inf')
N = 0


def set_inputs():
    global N
    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


def main():
    setrecursionlimit(100000)
    set_inputs()
    
    n = get_int()
    divs = filter(lambda x: n // x < x - 1, make_divisors(n))
    ans = sum(x - 1 for x in divs)
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


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


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import random
import itertools
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
n = int(input())

import math
def factorization(n):
    def factor_sub(n, m):
        c = 0
        while n % m == 0:
            c += 1
            n //= m
        return c, n
    
    buff = []
    c, m = factor_sub(n, 2)
    if c > 0: buff.append((2, c))
    c, m = factor_sub(m, 3)
    if c > 0: buff.append((3, c))
    x = 5
    while m >= x * x:
        c, m = factor_sub(m, x)
        if c > 0: buff.append((x, c))
        if x % 6 == 5:
            x += 2
        else:
            x += 4
    if m > 1: buff.append((m, 1))
    return buff




def divisor_sub(p, q):
    a = []
    for i in range(0, q + 1):
        a.append(p ** i)
    return a

def divisor(n):
    if n == 1:
      return([1])
    xs = factorization(n)
    ys = divisor_sub(xs[0][0], xs[0][1])
    for p, q in xs[1:]:
        ys = [x * y for x in divisor_sub(p, q) for y in ys]
    return sorted(ys)

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)
  table = set(table)
  table = list(table)
  return table

a = divisor(n)
ans = []
a.remove(n)
for i in a:
    b = (n-i)//i
    if n//b == n %b:
        ans.append(b)
print(sum(ans))

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

res = 0


for p in range(1, 10**6+2):
    if N % p == 0:
        q = N // p - 1
        if q > p:
            res += q
        else:
            break

print(res)

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = int(input())
yaku = set()
for x in range(1,int(math.sqrt(N))+1):
    if N % x == 0:
        yaku.add(x)
        yaku.add(N//x)

yaku = sorted(list(yaku))
L = len(yaku)
ans = 0
for i in range(1,L):
    if yaku[i] - yaku[i-1] !=1:
        tmp = yaku[i]-1
        if N//tmp == N%tmp:
            ans += tmp

print(ans)

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

divisors = []
for i in range(1, int(math.sqrt(N))+2):
    if N%i == 0:
        if i < N//i:
            divisors.append(i)
            divisors.append(N//i)
        elif i == N//i:
            divisors.append(i)
ans = 0
for elem in divisors:
    m = elem-1
    p = N//(m+1)
    if 0 <= p and p < m:
        ans += m
print(ans)

Solution (Python):
N=int(input())
S=set()
ans=0
index=1
while(index*index<=N):
    if N%index==0:
        S.add(index)
        S.add(N//index)
    index+=1
for k in S:
    if k==1:
        continue
    m=k-1
    if (N//m)==(N%m):
        ans+=m
print(ans)

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