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:
#!/usr/bin/env python3

import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union
# import time
# import math, cmath
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import _heapify_max, _heappop_max, _siftdown_max
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import Fraction               # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10)



def main():
    Num = Union[int, float]
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79e+308
    # inf = 2 ** 63 - 1             # (for fast JIT compile in PyPy) 9.22e+18
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    # def _heappush_max(h, item): h.append(item); _siftdown_max(h, 0, len(h)-1)
    
    def enum_divisor(num: int) -> List[int]:
        '''
        O(√n) で約数列挙を行う
        >>> enum_divisor(4)
        [1, 2, 4]
        >>> enum_divisor(19)
        [1, 19]
        >>> enum_divisor(100)
        [1, 2, 4, 5, 10, 20, 25, 50, 100]
        '''
        if num < 1:
            raise ValueError(f'enum_divisor(): argument should be >= 1. got {num}')    
        divisor_small = []
        divisor_large = []
        i = 1
        while i ** 2 <= num:
            if num % i == 0:
                divisor_small.append(i)
                if i != num // i:
                    divisor_large.append(num // i)
            i += 1
        divisor_large.reverse()
        return divisor_small + divisor_large


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



if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#素因数分解
def Prime_Factorization(n):
    R=[]
    N=n

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

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

    return R

#約数全部
from copy import copy
def Divisors(n):
    if n==1:
        return [1]
    
    L=Prime_Factorization(n)
    U=[1]

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


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
import unittest


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


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


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


if __name__ == "__main__":
    main()


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

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

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


divs = make_divisors(N)

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

print(sum(s))

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

k = makediv(n)

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

print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
from math import ceil
from collections import defaultdict
N=int(input())
done=defaultdict(int)
ans=0
#割る数がi 商とあまりがi 
for i in range(1,ceil(sqrt(N))+1):
    if N//i == N%i:
        if done[i]==0:
            ans+=i
            #print(i)
            done[i]=1
    if (N-i)%i==0:
        if done[(N-i)//i]==0 and (N-i)//i>i:
            ans+=(N-i)//i
            #print((N-i)//i)
            done[(N-i)//i]=1
print(ans)
#print(ceil(sqrt(1000000000000)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
n = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

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

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

#####Shorten#####
def DD(arg): return defaultdict(arg)


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

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

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

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

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
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

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

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

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

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

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

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

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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 i<n//i-1:
    ans+=(n//i-1)
print(ans)

Submission status: Accepted

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

diverta19_d()

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

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

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

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


#############
# Main Code #
#############

N = getN()

def make_divisors(n):
    divisors = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            divisors.append(i)
            # √nで無い数についてもう一個プラス
            if i != n // i:
                divisors.append(n // i)
    return sorted(divisors)

div = make_divisors(N)

num = []
alta = set(div)

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

Submission status: Accepted

Solution code:
n=int(input())
if n==1:
    print(0)
else:
    pf={}
    m=n
    for i in range(2,int(m**0.5)+1):
        while m%i==0:
            pf[i]=pf.get(i,0)+1
            m//=i
    if m>1:pf[m]=1
    ans=[]
    m=0
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            m=n//i-1
            if n%m==i and n//m==i:
                ans.append(m)

    #print(int(n**0.5))
    print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
p=0
for i in range(1,int(n**0.5)+2):
    j,k=divmod(n-i,i)
    p+=0 if k or j<=i else j
print(p)

Submission status: Accepted

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

n = int(input())
ans = 0
for i in div(n):
    if i == 1:
        continue
    elif n // (i - 1) == n % (i - 1):
        ans += i - 1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())


def factori(num):
    l = set()
    for i in range(1, int(num ** 0.5) + 1):
        if not num % i:
            l.add(i)
            l.add(n // i)
    return l


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

Submission status: Accepted

Solution code:
n = int(input())


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


def is_favorite(n, m):
    if x == 0:
        return False
    else:
        return n // m == n % m


li = make_divisors(n)
li = [x - 1 for x in li]


ans = 0
for x in li:
    if is_favorite(n, x):
        ans += x

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def divisor(i):
    s = []
    for j in range(1, int(i ** (1 / 2)) + 1):
        if i % j == 0:
            s.append(i // j)
            s.append(j)
    return sorted(set(s))

n = int(input())
s = divisor(n)
ans = 0
for i in s:
    if n > i * (i + 1):
        ans += n // i - 1
print(ans)

Submission status: Accepted

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

for i in range(1,N):
    if i >= (N - i) / i:
        break
    if (N - i) % i == 0:
        a = (N - i) // i
        ans += a

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
print(sum(N // n - 1 for n in range(1, int(N ** 0.5) + 1) if not N % n and n < N // n - 1))

Submission status: Accepted

Solution code:
N = int(input())
print(sum((N // n - 1) for n in range(1, int(N ** 0.5) + 1) if not N % n and n < N // n - 1))

Submission status: Accepted

Solution code:
n=int(input())


s=0
a=1
while a*a+a<n:
    if n%a==0:
        s+=n//a-1
    a+=1

print(s)

Submission status: Accepted

Solution code:
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
############################  
from math import floor

N=int(input())
p= floor(N**0.5)

ans=0
for i in range(1,p+1):
  if N%i==0:
    s = i
    t = N//i-1
    #print(s,t)
    u = N//i
    v = i-1
    #print(u,v)
    if s<t:
      ans += t
    if u<v:
      ans += v
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

divs = make_divisors(N)

ans = 0

for d in divs:
    if d == 1:
        continue
    m = d - 1
    if N // m == N % m:
        ans += m

print(ans)

Submission status: Accepted

Solution code:
n=int(input())

#n=m*a+a
#n=(m+1)*a
#m>a

if n==1 or n==2:
    print(0)
    exit()

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

Submission status: Accepted

Solution code:
N = int(input())

ans = 0

for i in range(1, N + 1):
    x =  (N - i) // i
    if x <= i:
        break
    if (N - i) % i == 0:
        ans += x

print(ans)

Submission status: Accepted

Solution code:
import unittest


def solve(n):
    used = set()
    total = 0
    for i in range(1, int(n ** 0.5)+1):
        if n % i > 0:
            continue
        d = n // i
        cand = [i-1, d-1]
        for c in cand:
            if c not in used and c > 0 and n % c == n // c:
                total += c
                used.add(c)

    return total


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


if __name__ == "__main__":
    main()


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def factors(N): #約数を全て求める。ただし、順不同
    from collections import deque
    ret = deque()
    middle = int( N**(1/2))
    for i in range(1, middle):
        if N%i == 0:
            ret.append(i)
            ret.append(N//i)
            
    if N%middle == 0:
        ret.append(middle)
        if middle != N//middle:
            ret.append(N//middle)
    return ret

def main():
    N = int( input())
    ans = 0
    for m in factors(N):
        if m==1:
            continue
        if N//(m-1)*m == N:
            ans += m-1
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from collections import deque
import heapq
import math
import fractions
import bisect
import itertools
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))



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

N=int(input())
if N==1:
    print(0)
    exit()
l=make_divisors(N)
ans=0
for i in range(1,len(l)):
    a,b=divmod(N,l[i]-1)
    if a==b:
        ans+=l[i]-1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

div = []
i = 1

while i * i < N:
    if N % i == 0:
        div.append(N // i)
    i += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする


def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N=len(v)
    size=len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    ns=int(N**0.5+1)
    ans=0
    for i in range(1,ns):
        ni=N-i
        d,m=divmod(ni,i)
        if m==0 and d>i:
            ans+=d
    print(ans)





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
#======================================================#

def main():
    n = II()
    sumv = 0
    divs = enumerate_divs(n)
    for p,q in divs:
        if p!=1:
            if n//(p-1) == n%(p-1):
                sumv += p-1
        if q!=1:
            if n//(q-1) == n%(q-1):
                sumv += q-1
    print(sumv)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import sqrt

def cal_dummy(N):
    output = 0
    for m in range(1,N):
        if N // m == N % m:
            output += m
    return output

def cal(N):
    #N == m*q+r(0 <= r < m)としてq==rのとき
    #N == (m+1)*r(0 <= r <= m-1)
    if N == 1:
        return 0
    else:
        output = 0
        for r in range(1,int(sqrt(N))+1):
            if N % r == 0:
                m = (N // r) - 1
                if (N//m) == r:
                    output += m
        return output

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

    print(cal(N))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

ans = 0
for k in range(1, int(n**(1/2))+1):
    m = (n - k) // k
    if m <= 0: continue
    if n // m == n % m:
        ans += m

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==0:
        if i>1 and n//(i-1)==n%(i-1):
            ans += i-1
        if n//i>1 and n//(n//i-1)==n%(n//i-1):
            ans += n//i-1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
factors = []
for i in range(1, int(n**0.5)+1):
    if n%i==0:
        if n//i*2<(4*n+1)**0.5-1:
            factors.append(i)
        if i*2<(4*n+1)**0.5-1:
            factors.append(n//i)
print(sum(factors)-len(factors))

Submission status: Accepted

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