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.



Sample input:
8


Sample output:
10

Submission status: Accepted

Solution code:
from collections import defaultdict
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

N = read_int()[0]

# 約数列挙 return 配列
def divisor(n):
    res = []
    i = 1
    while i**2 <= n:
        if n % i == 0:
            res.append(i)
            if i != n // i:
                res.append(n // i)
        i += 1
    return res

div = sorted(divisor(N))
def solve():
    ans = 0
    for d in div:
        if d == N: continue
        x = (N - d) // d
        if N % x == d:
            # print(x, d)
            ans += (N - d) // d
    return ans

if __name__ == "__main__":
    res = solve()
    print(res)

Submission status: Accepted

Solution code:
n = int(input())
x = 1
ans = 0
while x < n:
    m = (n - x) // x
    if m <= x:
        break
    if ((n-x) % x) == 0:
        ans += m
    x += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
	N = int(input())
	sqrt_n = int(N**0.5)
	ans = 0
	for i in range(1, sqrt_n+1):
		mod = N % i
		if mod == 0 and not(i == N//i or i+1 == N//i):
			ans += N//i - 1

	print(ans)


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
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())

div = make_divisors(N)
L = len(div)

if L % 2 == 0:
    if div[L//2] - div[L//2-1] == 1:
        print(sum(div[L//2+1:])-L//2+1)
    else:
        print(sum(div[L//2:])-L//2)
else:
    print(sum(div[L//2+1:])-L//2)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
if n >= 3:
    i = 1
    while n // i >= i + 2:
        if n % i == 0:
            ans += n // i - 1
        i += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0

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

    return divisors

if N > 1:
	divisors = make_div1(N)
	for i in divisors[1:]:
		if N // i == (N % i):
			ans += i
	print(ans)
else:
	print(0)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

import numpy as np

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())
if N == 1 or N == 2:
    print("0")
else:
    N_divisors = make_divisors(N)

    N_length = len(N_divisors)
    N_length_half = N_length // 2
    N_length_mod = N_length % 2

    N_length_half_temp = 0

    if N_length_mod == 1:
        N_length_half_temp = N_length_half + 1
    else:
        N_length_half_temp = N_length_half
    if N_divisors[N_length_half_temp]-1 == N_divisors[N_length_half_temp-1]:
        N_length_half_temp += 1
    print(sum(N_divisors[N_length_half_temp:]) - (N_length - N_length_half_temp))

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
c=0
i=1
while i**2<=n:
    if ((n-i)/i)%1==0 and n/(i+1)<(n-i)/i and (n-i)/i<=n/i:
        c=c+(n-i)/i
    i+=1
print(int(c))

Submission status: Accepted

Solution code:
import math
N = int(input())
r = math.sqrt(N)
p = math.floor(r)
ans = 0
for k in range(1, p + 1):
  if N % k == 0:
    if (N//k - 1) > k:
      ans += (N//k - 1)
print(ans)

Submission status: Accepted

Solution code:


def read_input():
    n = int(input())
    return n

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 submit():
    n = read_input()
    divisors = make_divisors(n)
    
    s = 0
    for d in divisors:
        m = (n - d) // d
        if d >= m:
            break
        s += m

    print(s)

if __name__ == '__main__':
    submit()

Submission status: Accepted

Solution code:


def get_divisors(num):
    """
    指定した整数のすべての約数を配列にして返す.

    :param num:
    :return:
    """
    import math
    max_num = math.floor(math.sqrt(num))
    re = set()
    for i in range(1, max_num + 1):
        if num % i == 0:
            re.add(i)
            re.add(num // i)
    return sorted(re)


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

    ls = get_divisors(N)

    # x * m == N - y
    # x * m == N - x
    # x * m + x == N
    # (m + 1) * x == N
    for m in ls[1:]:
        m -= 1
        if N // m == N % m:
            result += m
    print(result)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
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

m_total = 0
l = make_divisors(n)

for x in l:
    m = n//x - 1
    if x < m:
        m_total += m

print(m_total)

Submission status: Accepted

Solution code:
import math
import numpy as np
N = int(input())
m_list = []
max_p = math.floor(-1+math.sqrt(1+N))
for p in range(1, max_p+1):
   if N % p == 0:
       m = N//p -1
       m_list.append(m)
print(int(np.sum(m_list)))

Submission status: Accepted

Solution code:
import sys
def sample_code():
    n = int(input())
    if n == 1 or n == 2:
        print(0)
        sys.exit(0)
    # print('# 素因数')
    fct = factorize(n)
    # print(fct, num(fct))
    answer = 0
    # print('# 約数')
    for div in divisorize(fct):
        if num(div)-1 > n//num(div):
            answer += num(div) - 1
    print(answer)


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    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 = []  # prime factor
    b, e = 2, 0  # base, exponent
    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
    return a


if __name__ == '__main__':
    sample_code()

Submission status: Accepted

Solution code:
N = int(input())
answer = 0
divi=[]
for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        divi.append(i)
        if i != N // i:
            divi.append(N//i)

divi.sort()
divi.pop(0)
for i in reversed(range(len(divi))):
    if N % (divi[i]-1) != N // (divi[i]-1):
        divi.pop(i)
        i = i-1



for i in  range(len(divi)):
    answer = answer + divi[i]-1
print(answer)

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input())

output = 0
# n = (m+1)*x = y*x (y>=2)
limit = pow(n+0.25, 0.5)-0.5
x = 1
while x < limit:
    if n % x == 0:
        output += n // x - 1
    x += 1

print(output)

Submission status: Accepted

Solution code:
n = int(input())

def make_divisors(n):
    global 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 = []

make_divisors(n)

ans = 0

for i in range(len(divisors)):
    k = divisors[i]
    if n / k < k -1:
        ans += k -1

print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: 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)
    divisors.sort()
    return divisors

n = ni()
li = make_divisors(n)
l = len(li)
result = 0
for i in range(l):
    if i >= l // 2:
        break
    else:
        if li[-(i+1)] - li[i] > 1:
            result += (li[-(i+1)] - 1)
print(result)

Submission status: Accepted

Solution code:
N=int(input())

sqrt_N = N**0.5

list_D=[]
list_A=[]

i=1
while(i<sqrt_N):
    if N%i == 0:
        list_D.append(i)
    i+=1

for d in list_D:
    list_A.append(N//d-1)
    
if N==1 or N==2:
    print(0)
else:
    if N%list_A[-1] == 0:
        list_A.pop(-1)
    print(sum(list_A))

Submission status: Accepted

Solution code:
n=int(input())
sum=0
for x in range(1,10**6+1):
    if n%x==0:
        m=(n//x)-1
        if x<m:
            sum+=m
print(sum)

Submission status: Accepted

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

import math

n = ni()
a = 0
b = math.ceil(math.sqrt(n))

for i in range(1,b+1):
    if n%i == 0:
        c = n//i-1
        a = a if c <= i else a+c

print(a)

Submission status: Accepted

Solution code:
N = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
i, ans = 1, 0
while (i + 1) * i + i <= N:
  if (N - i) % i == 0:
    ans += (N - i) // i
  i += 1
print(ans)

Submission status: Accepted

Solution code:
import math
import sys
def II(): return int(sys.stdin.readline())

n = II()
sum = 0
# for n in range(1, n+1):
    # print('++++++n = '+str(n))
    # for m in range(1, n+1):
        # if n//m == n%m:
            # print('m = '+str(m)+":sho"+str(n // m)+"amari:"+str(n % m))

# for x in range(n):
for x in range(1,int(math.sqrt(n+1))):
    if n % x == 0:
        # print((n//x)-1)
        sum += ((n//x)-1)
print(sum)

Submission status: Accepted

Solution code:
def zzz(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

x=int(input())
list=zzz(x)
kotae=0
for l in list:
    if l>=2:
        if x%(l-1)==int(x/(l-1)):
            kotae+=(l-1)
            #print(l-1)
print(kotae)

Submission status: Accepted

Solution code:
import numpy as np
import re

N=int(input())
"""
count = 0
for a in range(1,n):
  if n%(a+1) == 0:
    count += a
print(count)
"""
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 np.array(divisors)
 

## 平方根が元を越える必要あり
divs = make_divisors(N)-1
print(np.sum(divs[np.where(divs>N**0.5)[0]]))

Submission status: Accepted

Solution code:
n = int(input())


# def main():
#     lft = 0
#     rgt = n
#     while rgt - lft > 1:
#         mid = (rgt + lft) // 2
#         if (n % mid) == 0 and ((n+1) % mid) == 0:
#             lft = mid
#         else:
#             rgt = mid
#     print(lft)

def main():
    p = prime_factor(n)
    ans = f([(i,j) for i, j in p.items()], 0, 1)
    print(ans)

def f(p, i, x):
    if i == len(p):
        tmp = n // x - 1
        if (tmp + 1) * x != n:
            return 0
        return tmp
    ans = 0
    tmp = 1
    for j in range(p[i][1]+1):
        ans += f(p, i+1, x*tmp)
        tmp *= p[i][0]
    return ans

def main():
    import math
    ans = 0
    for i in range(1, int(math.pow(n, 0.5)) + 2):
        if (n - i) % i == 0 and (n - i) // i > i:
            if n <= i:
                break
            ans += (n - i) // i

    print(ans)

def prime_factor(n):
    ret = {}
    i = 2
    while i * i <= n:
        while n % i == 0:
            ret[i] = ret.get(i, 0) + 1
            n /= i
        i += 1
    if n != 1:
        ret[n] = 1
    return ret


if __name__ == '__main__':
    main()
    2499694822001

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
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 and i != (n // i - 1) :
                divisors.append(n//i - 1)
    return divisors

n = int(input())
print(sum(make_divisors(n)))

Submission status: Accepted

Solution code:
import math
n=int(input())
rt=int(math.sqrt(n+1))-1
r=1
ans=0
while r<=rt:
    if n%r==0: ans+=n//r-1
    r+=1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
yakusu = []

for i in range(1,int(N**0.5)+1):
    if N%i == 0:
        yakusu.append(i)
        if i != N//i:
            yakusu.append(N//i)
yakusu.sort()

for i in range(len(yakusu)-1):
    if yakusu[i+1] - yakusu[i] > 1:
        for m in range(yakusu[i+1], yakusu[i], -1):
           if N//m == N%m:
               ans += m 
               break

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

i = 1
sum_value = 0
while (i+1) * i + i <= N:
    n = N - i
    d, m = divmod(n, i)
    if m == 0:
        sum_value += d
    i += 1

print(sum_value)

Submission status: Accepted

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

for i in range(1, n):
    m = n - i
    mm = m // i
    if mm <= i:
        break
    
    if m % i == 0:
        cnt += mm

print(cnt)

Submission status: Accepted

Solution code:
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 d in divisors:
    t = d - 1
    if t != 0 and N % t == N // t:
        ans += t
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#[R,G,B,N] = list(map(int,input().split()))
N = int(input())
ans = 0
for i in range(1,int(N**(1/2))+1):
    if N % i == 0:
        if (N//i - 1) > i:
            ans += (N//i-1)
print(ans)

Submission status: Accepted

Solution code:
import math
N = int(input())
 
count = 0
m = 1
while m**2 < N:
  if (N - m) % m == 0:
    fav_num = (N - m) // m
    if fav_num > m:
      count += fav_num
  m += 1
    
print(count)

Submission status: Accepted

Solution code:
N = int(input())


def make_divisors(n):
    divisors = []
    s = n ** (1/2)
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            if i > s:
                divisors.append(i-1)
            if i != n // i and n//i-1 > s:
                divisors.append(n//i - 1)
    return divisors
S = make_divisors(N)
print(sum(S))

Submission status: Accepted

Solution code:
N = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            #divisors.append(i)
            divisors.append(n//i)
    #divisors.sort()
    return divisors
divisors = make_divisors(N)
if N // divisors[-1]  < (divisors[-1] - 1):
    print(sum(divisors) - len(divisors))
else:
    print(sum(divisors[:-1]) - len(divisors[:-1]))

Submission status: Accepted

Solution code:
N = int(input())

ans = int()

for i in range(1, int(N ** 0.5) + 1):

    if N % i == 0 and i < int(N / i - 1):

        ans += int(N / i) - 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
a = int(((4*N+1)**(1/2)-1)/2)
ans = []

for i in range(1, int(N**(1/2))+1):
    if N%i == 0 and a < N//i-1:
        ans.append(N//i-1)
print(sum(ans))

Submission status: Accepted

Solution code:
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 sorted(divisors,reverse=True)

N = int(input())
div = make_divisors(N)
ans = [(a - 1) for a in div if a > 1 and N % (a - 1) == N // (a - 1)]
print(sum(ans))

Submission status: Accepted

Solution code:
N=int(input())
count=0
for i in range(1,round(N**(1/2))):
    if N%i==0:
        count+=N//i-1
print(count)

Submission status: Accepted

Solution code:
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


a = make_divisors(n)

b = []
for i in a:
     if i-1 in a:
          b.append(i)

a = a[len(a)//2:]
if n//a[0] == a[0]:
     a = a[1:]

for i in b:
     if i in a:
          a.remove(i)

print(sum(a)-len(a))

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
for i in range(1, 10 ** 6 + 1):
    if i >= N:
        break
    if N % i == 0:
        m = N // i - 1
        if m > i:
            ans += m
            # print(i, m)

print(ans)

Submission status: Accepted

Solution code:
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
    
divisors = make_divisors(N)

total = 0
for divisor in divisors:
    m = N//divisor-1
    if m > divisor:
        total += m
print(total)

Submission status: Accepted

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

    # divisors.sort()
    return divisors

n = int(input())
div = make_divisors(n)
ans = 0
for i in range(len(div)): #約数列挙
    m = (n//div[i])-1
    if m != 0 and n%m == n//m:
        ans += m
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
p = int(n ** 0.5) + 5
for i in range(1, p):
  if (n - i) % i == 0:
    q = (n - i) // i
    if q > i:
      ans+= q
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

wa = 0
end = int(n**0.5)+1
for r in range(1,end):
  if n%r is 0 and n//r > r+1:
    wa += n//r-1
    

print(wa)

Submission status: Accepted

Solution code:
N = int(input())

anss = set()
for X in range(1, int(N**0.5)+2):
    if (N-X) % X == 0:
        m = (N-X) // X
        if m <= 0: continue
        if N//m == N%m:
            anss.add(m)

for m in range(1, int(N**0.5)+2):
    if N//m == N%m:
        anss.add(m)

print(sum(anss))

Submission status: Accepted

Solution code:
N = int(input())

cond = []
for i in range(1, N):
    if i*i >= N:
        break
    if N % i == 0:
         cond.append((i, N//i))
# print(cond)

ans = set()
for a,b in cond:
    m = a+1
    if N//m == N%m:
        ans.add(m)
    m = b+1
    if N//m == N%m:
        ans.add(m)

    x = a
    if N%x == 0 and N//x > 1 and x < N//x-1:
        ans.add(N//x - 1)
    x = b
    if N%x == 0 and N//x > 1 and x < N//x-1:
        ans.add(N//x - 1)
    # print(a,b,ans)
# print(ans)
a = sum(list(ans))
print(a)

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np

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

lst_div = make_divisors(N)
#lst_plus1 = list(map(lambda x: x+1, lst_div))
#lst_toomit = list(lst_div & lst_plus1)
#print(lst_toomit)

ans = 0
for i in range(len(lst_div)):
  if (lst_div[i]-1 not in lst_div) and (lst_div[i]*(lst_div[i]-1) > N):
    ans += lst_div[i]-1

print(ans)

Submission status: Accepted

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

    # divisors.sort()
    return divisors
d = make_divisors(n)
for x in d:
    if x > 1 and n // (x-1) < (x-1):
        ans += x-1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
t = 0
N = int(input().strip())
for i in range(pow(10, 6)):
    i = i+1
    x = (N // i)
    if i == N:
        break
    if N % i == 0:
        x -= 1
    if N//x == N%x:
        t += x
print(t)

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
from functools import reduce
from itertools import combinations

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


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 solve():
    N = ii()
    ans = 0
    divisors = make_divisors(N)
    sqrt_n = N ** 0.5
    for m in divisors:
        if m == 1 or m - 1 < sqrt_n:
            continue
        ans += m - 1
    return ans


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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
import bisect
INF = float("inf")


def solve(N: int):

    if N == 1:
        print(0)
        return
    count = 0
    for r in range(1, int(math.sqrt(N))+1):  # 商
        # 余りは二分探索で良い
        lower = -(-N//r+1)
        upper = N//r
        while lower + 1 < upper:
            mid = (lower+upper)//2
            if N % mid >= r:
                lower = mid
            else:
                upper = mid
        if N % lower == r:
            count += lower
    print(count)

    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))  # type: int
    solve(N)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
# 素数リスト生成
def sieve(x):
    if x < 2: return []
    primes = [i for i in range(x)]
    primes[1] = 0
    for p in primes:
        if p > x ** (1/2): break
        if p == 0: continue
        for np in range(2 * p, x, p): primes[np] = 0
    return [p for p in primes if p != 0]

PS = sieve(10**6)

# 素因数分解
def factorint(x):
  d = {}
  for k in PS:
    if(x % k== 0):
      m = 1
      while(x % (k**m) == 0):
        m += 1
      d[k] = m - 1
      x = x / (k ** (m - 1))
      if x == 1:
        break
  return d

f = factorint(n)
# 10^6より大きい素因数があったときの処理
re = 1
for k, v in f.items():
  re *= k**v
if n // re != 1:
  f[n // re] = 1

# print(f)
s = 1
num = 1
for k, v in f.items():
  s *= (k ** (v + 1) - 1) // (k - 1)
  num *= (v + 1)
loss = 0
for i in range(1, int((-1 + (1 + 4 * n) ** (1/2)) / 2) + 1):
  if n % (i + 1) == 0:
    loss += i
print(s - num - loss)

Submission status: Accepted

Solution code:
import math
result=0
N=int(input())
sq=math.sqrt(N)
for i in range(1,int(sq)+2):
    if N%i==0:
        if N/i-1<=i:
            break
        result+=int(N/i)-1
print(result)

Submission status: Accepted

Solution code:
from math import sqrt
N = int(input())
kMaxBound = sqrt(N+1/4) - 1/2
kMax = int(kMaxBound)
if kMax == kMaxBound:
    kMax -= 1
ans = 0
for k in range(1,kMax+1):
    if N % k == 0:
        ans += N//k - 1
print(ans)

Submission status: Accepted

Solution code:

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())
a = make_divisors(N)
if N < 100000:
    ans = 0
    for n in range(1, N):
        a = N%n
        b = N//n

    #     print(n, a, b, a == b)
        if a == b:
            ans += n
#     print([ a +1 for a in anss], sum(anss), len(anss))
    print(ans)
else:
    if len(a)%2 == 0:
        print(sum(a[len(a)//2:]) - len(a)//2)
    else:
        print(sum(a[len(a)//2 + 1:]) - len(a)//2)

Submission status: Accepted

Solution code:
from collections import defaultdict
N=int(input())
if N==1 or N==2:
    print(0)
    quit()
def prime_factor(n):
    i = 2
    table = defaultdict(int)
    while i * i <= n:
        while n % i == 0:
            n //= i
            table[i]+=1
        i += 1
    if n > 1:
        table[n]+=1
    return table
table=prime_factor(N)
list=[1]
for fact,num in table.items():
    list_=[]
    for k in range(num+1):
        list_.extend([i*fact**k for i in list])
    list=list_
list.sort()
ans=0
for i in range(len(list)):
    if i==0:
        continue
    if list[i-1]+1==list[i]:
        continue
    m=list[i]-1
    if N//m==N%m:
        ans+=list[i]-1
print(ans)

Submission status: Accepted

Solution code:
# for i in range(1,101):
#   for j in range(1,i):
#     a=i//j
#     b=i%j
#     if a==b:
#       print(str(i)+'を'+str(j)+'で割った商は'+str(a)+'、余りは'+str(b))

n=int(input())

c=0
for i in range(1,n):
  x=(n-i)%i
  y=(n-i)//i
  if y<=i:
    break
  if x==0:
    c+=y
print(c)

Submission status: Accepted

Solution code:
def make_divisors(n):
    ans=0
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            if i>2:
                if n//i < i-1:
                    ans+=i-1
            if i!=n//i:
                if i < n//i-1:
                    ans+=n//i-1
    return ans

n=int(input())
print(make_divisors(n))

Submission status: Accepted

Solution code:
N = int(input())


# for i in range(1,N + 1):
#     # print("{}, {}, {}, {}".format(i, N // i, N % i, "OK" if N//i == N%i else ""))
#     if N//i == N%i:
#         print("{}, {}, {}".format(i, N // i, N % i))

def divisor_list(n):
    ret = set()
    i = 1
    while i * i <= n:
        if n % i == 0:
            ret.add(i)
            ret.add(n // i)
        i += 1
    return ret

ans = 0
L = divisor_list(N)
for l in L:
    oki = l-1
    if oki > 0 and N // oki == N % oki:
       ans += oki

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
x = 0
for i in range(1,n+1):
  if (n-i)//i<=i:
    break
  if (n-i)%i == 0:
    if (n-i)//i != i:
      x += (n-i)//i
print(int(x))

Submission status: Accepted

Solution code:
n=int(input())
if(n==2):
  print(0)
  quit()
ans=0
p=[]
for i in range(2,1000001):
  if(i*i>=n):
    break
  if(n%i==0):
    p.append(n//i)
for i in p:
  if(n%(i-1)==n//(i-1)):
    ans+=i-1
print(ans+n-1)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29

N = int_raw()

def main():
    ans = 0 
    for idx in range(1,N+1):
        if(idx*idx)+idx>=N:
            break
        if (N-idx)%idx == 0:
            ans += (N-idx)//idx
    return ans


print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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 in divs:
    x = N//div-1
    if x > 0 and N // x == div:
        ans += x
print(ans)

Submission status: Accepted

Solution code:
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())
t=make_divisors(n)
for i in range(len(t)):
    t[i]-=1
    if t[i]!=0:
        if n/t[i]>=t[i]:
            t[i]=0
print(sum(t))

Submission status: Accepted

Solution code:
n=int(input())
ans=0
def divisor(n):
    d0=[]
    d1=[]
    for i in range(1,int(n**.5)+1):
        x,y=divmod(n,i)
        if y==0:
            d0.append(i)
            d1.append(x)
    if d1[-1]==d0[-1]:
        d1=d1[:-1]
    return d0+d1[::-1]
d=divisor(n)
for i in d:
    if i>2 and n//i<i-1:
        ans+=i-1
print(ans)

Submission status: Accepted

Solution code:
import math
def num_divisors(n):
    ans = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            if i > 2 and i-1 > n // i: ans.append(i-1)
            if n != i**2 and n//i-1 > n // (n//i):
                ans.append(n//i-1)
    
    return ans

N = int(input())
lst = num_divisors(N)

print(sum(lst))

Submission status: Accepted

Solution code:
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

plist = make_divisors(N)

ans = 0
for p in plist:
    if p == N : continue
    m = N//p - 1
    if m > p:
        ans += m
        
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt

def simple(N):
    c = 0
    for r in range(1, int(sqrt(N)) + 100):
        if N % r == 0:
            x = N // r - 1
            if x > r:
                c += x
    print(c)
    
simple(int(input()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = set()
l = []
for i in range(1, int(n**(0.5))+1):
    p = (n-i) // i
    if (n-i) % i == 0 and i < p :
         l.append(p)
print(sum(l))