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: Time Limit Exceeded

Solution code:
N=int(input())
num=[]
for i in range(1,N):
    a=N%i
    b=N//i
    if a==b:
        num.append(i)
    else:
        pass
print(sum(num))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

ans = []
for m in range(2, n):
    if n // m == n % m:
        ans.append(m)

print(sum(ans))

Submission status: Time Limit Exceeded

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

    m2 = 0
    for m in range(2,N):
        if N // m == N % m:
            m2 = N // m
            break
    else:
        return 0

    ans = 0
    #print('m2 = ',m2)
    for m in range(1,m2+1):
        if N % m == 0:
            b = N // m - 1
            if N // b == N % b:
                #print('{} = {} * {} + {}'.format(N,b,N // b,N % b))
                ans += b
    return ans

print(solve())

Submission status: Time Limit Exceeded

Solution code:
import math
N = float(input())

n = math.sqrt(N)
sum = 0
for i in range(int(n), int(N)):
  div = int(N/i)
  res = N - i*div
  if(div == res):
    sum = sum + i
  
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

sum = 0
for i in range(1,N+1):
  if N//i == N%i:
    sum += i
print (sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
answer = 0
for i in range(1,N+1):
    if N//i == N%i:
        answer += i
print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
answer = 0
for i in range(N):
    a = i+1
    if(N //a == N % a):
        answer = answer + a
print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

sum = 0
for num in range(1,N+1):
    if (N//num) == (N%num):
        sum += num

print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
result = 0
for i in range(2, N):
    q, mod = divmod(N, i)
    if q == mod:
        result += i

print(result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

ans = 0
k = 1
while True:
  if N % k == 0:
    m = (N//k) - 1
    if m > k:
      ans += (N//k) - 1
    else:
      break
  k += 1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(N):
   S = S+i+1 if N//(i+1)==N%(i+1) else S

print(S)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

ans = 0
for r in range(1,N+1):
  if (N-r)%r != 0:
    continue
  else:
    m = (N-r)//r
    if m <= r:
      break
    else:
      ans += m
      
print(ans)

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
box = 0
for i in range(1,N):
    q,mod = divmod(N,i)
    if q == mod:
        box += i
print(box)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
cnt = 0
for i in range(2, N+1):
    m = N//i
    e = N%i
    if m==e:
        cnt +=i
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

def make_divisors(n):
    from collections import deque
    divisors = deque([])
    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)
    lst_divisors = list(divisors)
    lst_divisors.sort()
    return lst_divisors

lst = make_divisors(n)

#g = (n//m)*m + (n//m)
#g = (n//m)*(m+1)

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

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	return maa(n)
	#b , c = tin()
	#s = input()
	for i in range(1,10000):
		if maa(i)!=mab(i):
			pa(maa(i), mab(i))
			return i
	print('ok')
	
def maa(n):
	ret = 0
	rr=[]
	for i in range(1, n+1):
		if n//i <= i:
			break
			
		if (n-i) % i == 0:
			if i == (n-i)//i:
				return ret
			#pa(i, (n-i)//i)
			ret += (n-i)//i
			#rr.append((n-i)//i)
			
	return ret
	
def mab(n):
	ret = 0
	for i in range(1, n+1):
		if n // i == n%i:
			ret += i
	return ret
	
	
#+++++
isTest=False

def pa(*vl):
	if not isTest:
		return
	print(*vl)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
n = int(input())

total = 0

for i in range(1, int(n**0.5)+1):
    if n%i == 0:
        a = i
        b = n//i

        if a != 1 and (n//(a-1))*a == n:
            total += a-1
        if b != a and (n//(b-1))*b == n:
            total += b-1

print(total)

Submission status: Accepted

Solution code:
import math
n = int(input())
s = 0
if math.sqrt(n) == int(math.sqrt(n)):
  lim = int(math.sqrt(n))
else:
  lim = int(math.sqrt(n))+1
for i in range(1,lim):
  x = n-i
  if x%i == 0 and x//i > i:
    s += x//i
print(s)

Submission status: Accepted

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

Submission status: Accepted

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


def read():
    N = int(input().strip())
    return N,


def solve(N):
    # (m+1)p=N, 0 < p < mを満たすmを列挙する
    ans = 0
    p = 1
    while p * p <= N:
        if N % p == 0:
            m = N // p - 1
            if p < m:
                ans += m
            else:
                break
        p += 1
    return ans


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

Submission status: Accepted

Solution code:
n=int(input())

t1=2
comb=set()
while t1*t1<=n:
    if n%t1==0:
        t2=n//t1

        m=t1-1
        if t2==n%m:
            comb.add(m)
        m=t2-1
        if t1==n%m:
            comb.add(m)
    t1+=1

if n>2:
    print(sum(comb)+n-1)
else:
    print(sum(comb))

Submission status: Accepted

Solution code:
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())
divs = make_divisors(n)

def judge(d):
  if n // (d-1) == n % (d-1):
    return True
  else:
    return False

ans = 0
for d in divs:
  if d > 1 and judge(d):
    ans += d-1
print(ans)

Submission status: Accepted

Solution code:
import sys, math, re
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(10**9)
MOD = 10**9+7

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

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

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 main():
    N = ii()
    d = make_divisors(N)
    ans = 0

    for a in d:
        m = (N-a)//a
        if a < m:
            ans += m

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import product

from functools import reduce
import operator
int_product = lambda it: reduce(operator.mul,it,1)

# 素因数分解
def prime_factors(n):
    i = 2
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            yield i
    if n > 1:
        yield n

def divisors(n):
    factors = prime_factors(n)
    factors = Counter(factors)
    pows = tuple(factors.values())
    factors = tuple(factors.keys())
    for pp in product(*(range(p+1) for p in pows)):
        yield int_product(f**p for f,p in zip(factors,pp))


N = int(input())
res = 0
for d in divisors(N):
    m = d-1
    if m > 0 and N//m == N%m:
        res += m

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def resolve():
    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())

    # N //m = k,  N%m = k  kは同じ値
    # N = k*m + k : 商と余りを計算したらNになる
    # N = k(m+1)より、m = (N//k)-1 -> m = 約数 - 1

    div = make_divisors(N)
    ans = 0
    for k in div[1:]:  # 1より大きい値からスタート
        m = k - 1
        if m <= 0:
            continue
        if N // m == N % m:
            ans += m

    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
if N > 3:
    ans += N-1

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

N=intput()
ans=0
for x in range(1,int(N**0.5)+1000):
    if (N-x)%x==0:
        m=(N-x)//x
        if m<=x:
            break
        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]

arr = make_divisors(n)
total=0
for m in arr:
    r = n//m

    if r<m-1:
        total +=m-1


print(total)

Submission status: Accepted

Solution code:
def 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())
div = divisors(n)

ans = 0
for d in div:
    if d-1 == 0:
        continue
    if n%(d-1) == n//(d-1):
        ans += d-1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[79]:


N = int(input())


# In[80]:


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]


# In[82]:


if N < 3:
    print(0)
else:
    mylist = make_divisors(N)
    idx = len(mylist)//2
    ans = 0
    for x in mylist[idx:]:
        if N//(x-1) == N%(x-1):
            ans += x-1
    print(ans)


# In[ ]:

Submission status: Accepted

Solution code:
def a(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())
L=a(N)
#N=r(m+1)
ans=0
for i in L:
  if (N//i)-1>i:
    ans+=(N//i)-1
print(ans)

Submission status: Accepted

Solution code:
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


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


def make_divisors(n: int):
    lower_divs = []
    upper_divs = []
    i = 1
    while i**2 <= n:
        if n % i == 0:
            lower_divs.append(i)
            if i != n // i:
                upper_divs.append(n // i)
        i += 1
    return lower_divs + upper_divs[::-1]


def main():
    n = input_int()
    divs = make_divisors(n)
    ans = 0
    for div in divs:
        m = (n // div) - 1
        if m == 0:
            continue
        if n // m == n % m:
            ans += m
    print(ans)

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
q = 1
while(q ** 2 + q < N):
  m = (N - q) / q
  if(m.is_integer()):
    ans += int(m)
  q += 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

ans=0
n = int(input())
divisors = make_divisors(n)
for i in divisors[1:]:
    i -= 1
    if n % i == n//i:
        ans += i

print(ans)

Submission status: Accepted

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

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return float(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()



def main():
	n=II()

	ans=0
	for i in range(1,10**6+10):
		a=n-i
		if a%i==0:
			b=a//i
			if b>i:
				ans+=b
			else:
				break
	print(ans)



	
	
	



	
	
	









if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

class factorials:
    '''
    args:
      n : max val when exploring factorials
    '''
    def __init__(self, n):
        self.n = 1# factorials to be searched
        self.factorials = []
        self.update_factorials(n)

    def update_factorials(self, n):
        if self.n >= n:
            return None
        for i in range(self.n+1, n+1):
            done = False
            limit = int(i ** 0.5)
            for j in self.factorials:
                if j > limit: break
                if not i % j:
                    done = True
                    break
            if not done:
                self.factorials.append(i)
        self.n = n
        return None

    def factorials_list(self):
        return self.factorials

    def check_fact(self, x):
        if x > self.n**2:
            self.update_factorials(int(x ** 0.5)+1)
        MAX = int(math.sqrt(x))
        for f in self.factorials:
            if f > MAX:break
            if not x % f:
                return False
        return True

    def prime_factorization(self, val, divisors=None):
        # divisors : default-dict of divisors. Should be specified only if appended vals are required
        max_n = int(math.sqrt(val))
        if self.n < max_n:
            self.update_factorials(max_n)
        if divisors == None:
            divisors = defaultdict(lambda: 0)
        for f in self.factorials:
            if f > val: break
            while True:
                if not val % f:
                    divisors[f] += 1
                    val //= f
                else:
                    break
        if val > 1:
            divisors[val] += 1
        return divisors



def run():
    N = int(input())
    if N == 1:
        print(0)
        return
    facts = factorials(int(N ** 0.5))
    dic = facts.prime_factorization(N)
    #print(dic)
    ret = 0

    def dfs(x, l, v):
        nonlocal ret
        #print(x,l,v)
        xx, ll = x[0], l[0]
        if len(x) == 1:
            for i in range(ll+1):
                tmp = v * (xx ** i)
                #print(tmp)
                if tmp == 1:continue
                if N % (tmp-1) == N // (tmp-1):
                    #print(tmp)
                    ret += tmp-1

        else:
            for i in range(ll + 1):
                tmp = v * xx ** i
                dfs(x[1:], l[1:], tmp)

    dfs(list(dic.keys()), list(dic.values()), 1)

    print(ret)

if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
N=int(input())

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

ans = 0
i = 1
while True:
  m = N//i-1
  q,r = divmod(N,m)
  if q == r:
    ans += m
  if m<N**.5:
    break
  i += 1
  
print(ans)

Submission status: Accepted

Solution code:
class common_function():
    """
        1. よく使いそうで予め用意してあるものをまとめた
        2. よく使いそうな関数群をまとめた
    """
    def make_divisors(self, n:int):
        """
            試し割り法による約数の列挙を行うメソッド
            ある値 n の約数の列挙を行うのに O(n^(1/2)) かかる.
            e.g.
                input: 96
                output: [1, 96, 2, 48, 3, 32, 4, 24, 6, 16, 8, 12]
        """
        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():
    common = common_function()
    N = int(input())
    m = common.make_divisors(N)
    ans = 0
    for i in m:
        if i == 1:
            continue
        ans += (N%(i-1) == N//(i-1)) * (i-1)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
def div(n):
    low,high= [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            low.append(i)
            if i != n // i:
                high.append(n//i)
        i += 1
    return low+high[::-1]
S=div(N)
ans=0
S=S[1:]
for i in S:
   if i==0:
      continue
   if N%(i-1)==N//(i-1):
      ans+=i-1
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    # r == N % m == N // m の時、
    # N = r * m + r = r * (m + 1) と書ける(0 < r < m)。
    # Nを2つの正の整数に分解し、上記を満たすmを求めて総和を求める。
    ans = 0
    r = 0
    while (r + 1) ** 2 <= N:
        r += 1
        if N % r > 0:
            continue
        m = N // r - 1
        if r < m:
            ans += m
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
ceil = math.ceil

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

d = divisor(n)
ans = 0
for num in d:
    if num>1 and n%(num-1)==n//(num-1):
        ans+=num-1
print(ans)

Submission status: Accepted

Solution code:

c,n = 0,int(raw_input())
def check(v,n):
	return v and n/v == n%v

for d in range(1, (int(n **0.5) +1)):
	if n % d == 0:
		for v in set([d, n/d]):
			if check(v-1,n):
				c += v-1

print c

Submission status: Accepted

Solution code:
N = int(input())

result = 0
for i in range(1, N+1):
    m = N // i - 1
    if m == 0:
        continue
    if N // m == N % m:
        result += m
    elif m < i:
        break

print(result)

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline())

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

Submission status: Accepted

Solution code:
# N//m==N%m=k
# N=k*m+k=k(m+1)=kM
N=int(input())
arr=[]
for i in range(1,int(N**0.5)+1):
    if N%i==0:
        arr.append(N//i)
        if N//i!=i:
            arr.append(i)
arr.sort()

ans=0
for M in arr:
    m=M-1
    if m==0:continue
    if N%m==N//m:
        ans+=m
print(ans)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math

#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
n = I()
def yaku(m):
    ans = []
    i = 1
    while i*i <= m:
        if m % i == 0:
            j = m // i
            ans.append(i)
            if j != i:
                ans.append(j)
        i += 1
    ans = sorted(ans)
    return ans
dic = yaku(n)
dic = Counter(dic[1:])
ans = 0
for k,v in dic.items():
    m = k-1
    if n//m == n%m:
        ans += m
print(ans)

Submission status: Accepted

Solution code:
N = int(input())


def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table


A = divisor(N)
A = [i - 1 for i in A]

ans = 0
for a in A:
    if a == 0:
        continue
    if N // a == N % a:
        ans += a

print(ans)

Submission status: Accepted

Solution code:
import math
from collections import Counter
N = int(input())
Nyakusu = []
Nruto = math.sqrt(N)
Nruto = math.ceil(Nruto)

for i in range(1, Nruto+1):
    if N % i == 0:
        Nyakusu.append(N//i-1)
        Nyakusu.append((N//(N//i))-1)
ans = 0
Nyakusu = Counter(Nyakusu)
for m in Nyakusu.keys():
    if m == 0:
        continue
    if N//m != N % m:
        continue
    ans += m
print(ans)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())

N = I()

# N = q*m+m = (q+1)*m になることに注目

divisor = []  # Nの約数
for i in range(1,int(N**.5)+1):
    if N % i == 0:
        divisor.append(i)
        if i != N//i:
            divisor.append(N//i)

ans = 0
for d in divisor:
    m = d-1
    if N//d < m:
        ans += m

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for i in range(1,min(N,1250000)):
    if(((N-i)/i).is_integer() and N//((N-i)/i) == N%((N-i)/i)):
        # print((N-i)//i,i)
        ans += ((N-i)//i)
        # if(i == 800000):
        #     print(ans)
    # print(i)
print(ans)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
x = 1
ans = 0
while x**2<=N:
    if N%x==0:
        div = N//x
        if div-1>x:
            ans += div-1
    x += 1

print(ans)

Submission status: Accepted

Solution code:
import math
def prime_divisor(n):
    ls = []
    i = 2
    while i <= math.floor(n**0.5):
        if n%i == 0:
            ls.append(i)
            ls.append(n//i)
            i += 1
        else:
            i += 1
    if n > 1:
        ls.append(n)
    return ls
N = int(input())
ls1 = prime_divisor(N)
ls2 = [x-1 for x in list(set(ls1)) if x >= 2]
ls2.sort()
ls2.reverse()
ans = 0
for i in range(len(ls2)):
    if N // ls2[i] == N % ls2[i]:
        ans += ls2[i]
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
sqrt = int(n ** 0.5)
for i in range(1, sqrt+1):
    if n % i == 0:
        m = n // i - 1
        if m != 0 and n // m == n % m:
            ans += m
        if n // i == i: continue
        m = i - 1
        if m != 0 and n // m == n % m:
            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]


# 約数から1引いたものが候補
arr = make_divisors(n)
arr = [x - 1 for x in arr if x >= 2]

#　商と剰余が不一致ならbreakできる
ans = 0
for x in arr[::-1]:
    if n // x != n % x:
        break
    ans += x

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


def main():
    n = int(input())
    a = []
    for i in range(1, (int)(math.sqrt(n)) + 1):
        if n % i == 0:
            if i != 1:
                a.append(i - 1)
            if n // i - 1 != 0:
                a.append((n // i) - 1)
    ans = 0
    for i in range(len(a)):
        if a[i] != 1 and (n // a[i] == n % a[i]):
            ans += a[i]
    print(ans)


main()

Submission status: Accepted

Solution code:
def prime(p):
    memo = [p]
    for i in range(2,(int(p**0.5)+1)):
        if p%i == 0:
            memo.append(i)
            memo.append(p//i)
    return memo

x = int(input())

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

memo = prime(x)

ans = 0

for i in memo:
    if x%(i-1)==x//(i-1):
        ans += i-1
print(ans)

Submission status: Accepted

Solution code:
import math
N = int(input())
ans = 0
for i in range(1,math.ceil(N**0.5)):
    a = N - i
    if a % i == 0 and a/i >0 and a/i>i:
        ans += a/i
print(int(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:
        # print('----',i)
        a = i
        x1 = n//i
        x = x1-1
        # print(a,x)
        if a < x:
            ans += x
        
        a = n//i
        x1 = i
        x = x1 - 1
        if a < x:
            ans += x

print(ans)