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:
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
def factorial(x): #階乗計算
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): #約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): #素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n=int(input())
    if n==2:
        print(0)
        return
    ans=0
    for i in range(int(n**(1/2))+3):
        i+=1
        if (n-i)%i == 0 and i < (n-i)//i:
            if i==n**(1/2):
                break
            ans+=(n-i)//i
    print(ans)
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())

na=[]
for i in range(1,int(N**0.5)+1):
  if N%i==0:
    if i<N//i-1:
      na.append(N//i-1)


print(sum(na))

Submission status: Accepted

Solution code:
n=int(input())
def pri(n):
  l=[]
  for i in range(1,int((n)**(1/2))+1):
    if n%i==0:
      l.append(i)
      if i!=n//i:
        l.append(n//i)
  return l
list1=pri(n)
sum=0
for i in list1:
  if n>i*(i+1):
    sum+=n//i-1
print(sum)

Submission status: Accepted

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

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


ans = 0
for i in make_divisors(n):
    if i >= n ** 0.5 + 1:
        ans += i-1

print(ans)

Submission status: Accepted

Solution code:
import math
n=int(input())
lim=int(math.sqrt(n))
cnt=0
if lim**2==n:
    for i in range(1,lim):
        if n%i==0:
            cnt+=n//i-1
    print(cnt)
else:
    for i in range(1,lim+1):
        if n%i==0:
            cnt+=n//i-1
        a=int(math.sqrt(n))
    if a*(a+1)==n:
        cnt-=a 
    print(cnt)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

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

N = I()
print(solve(N))

Submission status: Accepted

Solution code:
# div2019D - DivRem Number
from math import sqrt


def divisors(n: int) -> set:
    # Compute divisors of a number.
    divs = set()
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0:
            divs.add(i)
            divs.add(n // i)
    return divs


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# div2019D - DivRem Number
def divisors(n: int) -> set:
    # Compute divisors of a number.
    divs = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divs.add(i)
            divs.add(n // i)
    return divs


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# div2019D - DivRem Number
# cf. ARC026B - 完全数
def divisors(n: int) -> set:
    """
    Compute divisors of a number.
    
    Args: n (int): an integer to be evaluated.
    Returns: div (set): set of divisors
    """
    div = set()
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            div.add(i)
            div.add(n // i)
    return div


def main():
    N = int(input())
    divs = divisors(N)
    divs.discard(1)
    ans = 0
    for m in divs:
        m -= 1
        if N // m == N % m:
            ans += m
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#diverta2019 programming contest D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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 = I()
lst = make_divisors(n)
ans = 0
for i in lst:
    if i == 1:
        continue
    a,b = divmod(n,i-1)
    if a == b:
        ans += i-1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

divs = []
for i in range(1,int(N**0.5)+2):
  if N % i == 0:
    if i < N//i -1:
      divs.append(N//i-1)
    else:
      break
print(sum(divs))

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
N = int(input())
ds = set()
for d in range(1, N+1):
  if d*d > N:
    break
  if N%d == 0:
    ds.add(d)
    ds.add(N//d)
r = 0
for d in ds:
  m = d-1
  if m == 0:
    continue
  if N%m == N//m:
    r += m
print(r)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
n = int(input())
ans = 0
for i in range(1, int(n**0.5) + 1):
    if n % i == 0:
        j = n // i 
        if j - i <= 1:
            continue
        ans += j - 1
print(ans)

Submission status: Accepted

Solution code:
#19:32
n = int(input())
ans = 0
if n == 1:
  print(0)
else:
  for i in range(1,int(n**.5)+1):
    if n % i == 0:
      x = n // i - 1
      if n // x == n % x == i:
        ans += x
        #print(x)
  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:
        x, m = min(i, n // i), max(i, n // i) - 1
        if m > x:
            ans += m
print(ans)

Submission status: Accepted

Solution code:
def get_divisor(n):
    a,b = [],[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            a.append(i)
            b.append(n//i)
    if a[-1]==b[-1]:b.pop()
    a.extend(b[::-1])
    return a

N = int(input())
ans = 0
for m in get_divisor(N):
    m-=1
    if m==0 : continue
    if N//m == N%m: ans+=m
print(ans)

Submission status: Accepted

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

for i in range(len(divisors)):
    if m[i]- divisors[i] < 2:
        m[i] = 1 


print(sum(m)-len(m))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

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

def solve(N: int):
    divisors =  make_divisors(N)
    res = 0
    for i in divisors:
        t = i-1
        if t > 0 and N // t == N % t:
            res += t
    print(res)


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()

    return

#B
def B():
    n = I()

    return

#C
def C():
    n = I()

    return

#D
def D():
    def factorize(n):
        if n < 4:
            return [1,n]
        res = []
        for i in range(1,int(n**0.5)+1):
            if n%i == 0:
                res.append(i)
                if n//i != i:
                    res.append(n//i)
        res.sort()
        return res
    n = I()
    if n <= 2:
        print(0)
        quit()
    f = factorize(n)
    ans = 0
    for i in f:
        m = max(0,n//i-1)
        if i<m:
            ans += m
    print(ans)
    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#G
def G():
    n = I()

    return

#H
def H():
    n = I()

    return

#I
def I_():
    n = I()

    return

#J
def J():
    n = I()

    return

#Solve
if __name__ == "__main__":
    D()

Submission status: Accepted

Solution code:
N = int(input())

import math
Nq = int(math.sqrt(N+1))
#print ( Nq )

so = 0
for i in range(1,Nq+1):
  if (N%i != 0):
    continue
  if (N//i < i):
    continue
  
  m,r = (N//i)-1,i
  if ( r<m ):
    so += m
  
  m,r = i-1,(N//i)
  if (N//i != i):
    if (r<m):
      so += m

print ( so)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
if N >= 2:
    p = 1
    while p*p <= N:
        q, r = divmod(N, p)
        if r == 0 and p < q - 1:
            ans += q - 1
        p += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

def prime_factorization(n):
    '''
    Trial division.
    Input: 
        n : a positive integer
    Output:
        a dictionary of #(each prime factors) of n,
    '''
    result = defaultdict(int)
    if n < 2:
        return result
    while n % 2 == 0:
        result[2] += 1
        n //= 2
    p = 3
    while p*p <= n:
        while n % p == 0:
            n //= p
            result[p] += 1
        p += 2
    if n > 1:
        result[n] += 1
    return result

N = int(input())
ans = 0
if N >= 2:
    p = 1
    while p*p <= N:
        q, r = divmod(N, p)
        if r == 0 and p < q - 1:
            ans += q - 1
        p += 1
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:
    tmp = (N-i)/i
    if tmp != 0 and N%tmp == i:
      ans += int(tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys

N = int(input())
sum = 0

for i in range(1, N+1):
    if (N-i) % i == 0:
        m = int((N-i) / i)
        if(m <= i):
            print(sum)
            sys.exit()
        
        sum += m
    if((N-i)/i < i):
        print(sum)
        sys.exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N = int(input())
num = 0
i = 1
while i <= math.sqrt(N):
    if N % i == 0:
        a = i - 1
        b = (N // i) - 1
        if a == b:
            if a > 0 and N // a == N % a:
                num += a
        else:
            if a > 0 and N // a == N % a:
                num += a
            if b > 0 and N // b == N % b:
                num += b
    i += 1

print(num)

Submission status: Accepted

Solution code:
N = int(input())
nums = []

for i in range(1, int(N**0.5)+1):
    if not N % i:
        n = N // i
        if i == n:
            nums.append(i-1)
        else:
            nums.extend([i-1, n-1])

print(sum([n for n in nums[1:] if N // n == N % n]))

Submission status: Accepted

Solution code:
n = int(input())
l = int(-(-(n ** (1/2)) // 1))
total = 0
for i in range(1, l):
	if n % i == 0 and n != i * (i+1):
		total += (n - i) // i
print(int(total))

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
for x in range(1, int(N**.5)+1):
    if N % x == 0:
        y = N//x
        if x == y:
            if y < x-1:
                ans += x-1
        else:
            if y < x-1:
                ans += x-1
            if x < y-1:
                ans += y-1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
	
def main():
	N = int(input())
	
	tmp = make_divisors(N)
	ans = []
	
	for i in tmp:
		a = i - 1
		if a == 0:
			continue
		if N // a == N % a:
			ans.append(a)
	
	print(sum(ans))
	
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
	
if __name__ == "__main__":
	main()

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
fav = make_divisors(n)
result = 0
for x in fav:
    if x == n:
        continue
    m = int(n/x)-1
    if int(n/m)==n%m:
        result += m
print(result)

Submission status: Accepted

Solution code:
import math
ans=0
m=[]
N=int(input())
rN=math.floor(math.sqrt(N))
for i in range(1,rN+1):
    if N%i==0:
        m.append(i)
        m.append(int(N/i))
    else:
        pass
m.sort()
m2=list(map(lambda x: x-1,m))
for i in m2:
    if i==0:
        pass
    else:
        a,b=divmod(N,i)
        if a==b:
            ans+=i
        else:
            pass
print(ans)

Submission status: Accepted

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

N = int(input())
a = make_divisor(N)

sum = 0
for i in a:
    if N // i - 1 > i:
        sum += (N // i) - 1

print(sum)

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
ans = 0
divisors = make_divisors(N)

for d in divisors:
    m = (d - 1)
    if m and (N//m == N % m):
        ans += m
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
D - DivRem Number
https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d

"""
import sys


def solve(N):
    def divisor(N):
        divisors = set()
        for i in range(1, int(N**0.5)+1):
            if N % i == 0:
                divisors.add(i)
                divisors.add(N // i)
        return divisors

    ans = 0
    for q in divisor(N):
        if q == 1:
            continue
        a, b = divmod(N, q-1)
        if a == b:
            ans += (q-1)
    return ans


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
n = int(input())

ans = 0

for i in range(1,10**6+1):
    if i*i >= n:
        break
    if n % i != 0:
        continue
    
    m = (n // i) - 1
    if i < m:
        ans += m

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
if n == 1:
  print(0)
  quit()
else:
  res = n-1 if n%(n-1) == int(n/(n-1)) else 0
i = 2
while i*i <= n:
  if n%i == 0:
    if n%(i-1) == int(n/(i-1)):
      res += i-1
    if i*i != n:
      if n%(int(n/i)-1) == int(n/(int(n/i)-1)):
        res += int(n/i) - 1
  else:
    pass
  i += 1
print(res)

Submission status: Accepted

Solution code:
from math import sqrt
def main():
    n = int(input().rstrip())
    sqrt_n = int(sqrt(n))

    total = 0
    for number in range(1,sqrt_n + 1):
        if n % number > 0:
            continue
        remain = n - number
        x, y = divmod(remain, number)
        #print(x, y, remain, number)
        if y == 0 and x > number:
            #print("○",number)
            total += x
        #elif y == 0:
        #    print("×",number)

    print(total)

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
from collections import Counter
from itertools import product

N = int(input())

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

# 素因数分解で約数を計算する
primes = prime_decomposition(N)

# 素因数の種類と個数を数え上げる
counter = Counter(primes)
values = [[k**i for i in range(v+1)] for k, v in counter.items()]
p = product(*values)

# 全ての種類の素数×個数を計算して、約数の組み合わせを格納する
divisors = []
for v in p:
    div = 1
    for w in v:
        div *= w
    divisors.append(div)

# 条件にあう約数を選別してmを求め、答えに加算する
ans = 0
for i in divisors:
    j = N / i
    if (i > j + 1) & (i >= 1) & (j >= 1):
        ans += i - 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
tmp = N ** 0.5
sum = 0
k =1
while k < tmp:
    m = N // k -1 
    if N % k == 0 and m > tmp-1 and k < m: 
        sum += m
    k += 1
print(sum)

Submission status: Accepted

Solution code:
import math

N = int(input())

result = 0
D = math.ceil(math.sqrt(N))
for i in range(1, D):
  if N % i == 0:
    m = N // i - 1
    if N % m != 0:
      result += m

print(result)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())

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

Submission status: Accepted

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

import sys
import copy

sys.setrecursionlimit(1000000)


# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

def DIVISORS(n):
    ret = []
    i = 1
    while i * i <= n:
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
        i += 1

    ret.sort()
    return ret


N = int(input())
divisors = DIVISORS(N)

ans = 0
for x in divisors:
    m = x - 1
    if m == 0:
        continue
    r = N % m
    if r == N // m:
        ans += m

print(ans)

Submission status: Accepted

Solution code:
read = input
from math import sqrt
N = int(read())
sqrt_n = int(sqrt(N))
k = 1

ans = 0
m = 0

while k <= sqrt_n + 1000:
    if N % (k) == 0:
        m = N // (k)
#         print(m, k)
        if not m-1 > k:break
        ans += m - 1
    k += 1
print(ans)

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline())
i = 1
s = 0

while i ** 2 <= N:
    if N % i == 0:
        k = N // i - 1
        if k > i:
            s += k
    i += 1
print(s)

Submission status: Accepted

Solution code:
N = int(input())
total = 0
for q in range(1,N // int(N**0.5) + 1):
	try:
		if N % (N // q - 1) == N // (N // q - 1):
			total += (N // q) - 1
	except:
		pass
print(total)

Submission status: Accepted

Solution code:
import math
n = int(input())
ans = 0

if n > 2:
  ans += n-1

for i in range(2,math.ceil(n**0.5)+1):
  if n % i == 0:
    j = n // i
    if n % (i-1) == n // (i-1):
      ans += i-1
    if i != j > 1 and n % (j-1) == n // (j-1) :
      ans += j-1
  
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math as m
# m.floor m.ceil

n = int(input())
ans = 0
for i in range(1,m.ceil(m.sqrt(n))):
    if n%i==0:
        if n//i == i+1 : break
        ans += n//i -1

if n in [1,2]: ans = 0

print(ans)

Submission status: Accepted

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


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

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

            if n // m == n % m:
                ans += m

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import exit

N = int(input())


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

    return divisors


ans_list = make_divisors(N)

ans = []

for ans_l in ans_list:
	a = ans_l - 1
	if a == 0:
		continue
	if N // a == N % a:
		ans.append(a)

print(sum(ans))

Submission status: Accepted

Solution code:
import math
N = int(input())
result = 0

root = math.ceil(math.sqrt(N))
for i in range(root):
    if N % (i + 1) == 0 and (i + 1) + 1 < N // (i + 1):
        result += N // (i + 1) - 1

print(result)

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 divisor in divisors:
	if divisor != 1:
		shou = N // (divisor-1)
		amari = N % (divisor-1)
		if shou == amari and divisor-1 > amari:
				ans += divisor-1

print(ans)

Submission status: Accepted

Solution code:
import math
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

n = inn()
q = int(math.sqrt(n))+1
sum = 0
for i in range(1,q):
    ddprint("i {}".format(i))
    if n%i==0:
        m = n//i - 1
        ddprint("divides m {}".format(m))
        if m==0:
            continue
        if n%m == n//m:
            sum += m
print(sum)

Submission status: Accepted

Solution code:
import math
N = int(input())
sqrtN = int(math.sqrt(float(N)))

ans = 0
prefnum = []

for div in range(1, sqrtN+1):
  if( N % div == 0):
    quot = int(N/div)
    if((quot-1) > div):
      prefnum.append(int(quot-1))
      
for i in prefnum:
  ans = ans + i

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = input()

ans = 0
for d in xrange(1, int(n ** 0.5) + 1):
    if n % d == 0:
        m = n // d - 1
        if m * m > n: ans += m

print ans

Submission status: Accepted

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

"""解説
http://drken1215.hatenablog.com/entry/2019/05/12/004500

N//m = N%m = k （kは約数。かつ余り）とすると、

N = mk + k
N = k(m+1)

k は MOD m の余りなので、m > k である。
よって、

N = k*(m+1) > k*k

よって、

N > k**2
√N > k

これに気づけばOK。あとはkについて全探索。O(√N)


(例)
・N=8, m=3のとき
3*2 + 2 = 8
m*k + k = N

・N=8, m=7のとき
7*1 + 1 = 8
m*k + k = N

"""
import math

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

    ans = 0
    for k in range(1, math.floor(math.sqrt(N))+1):
        if N%k != 0: continue # kはNの約数より
        # N = k(m+1)
        # m = (N/k) - 1
        m = (N/k) - 1
        if m <= 0: continue
        if N//m == N%m:
            ans += m
    print(int(ans))


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

"""解説
http://drken1215.hatenablog.com/entry/2019/05/12/004500

N//m = N%m = k （kは約数。かつ余り）とすると、

N = mk + k ...(1)
N = k(m+1)

k は MOD m の余りなので、m > k である。
よって、

N = k*(m+1) > k*k

よって、

N > k**2
√N > k

これに気づけばOK。あとはkについて全探索。O(√N)


(例)
・N=8, m=3のとき
3*2 + 2 = 8
m*k + k = N

・N=8, m=7のとき
7*1 + 1 = 8
m*k + k = N

"""
import math

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

    ans = 0
    for k in range(1, math.floor(math.sqrt(N))+1):
        if N%k != 0: continue # kはNの約数より
        # N = k(m+1)
        # m = (N/k) - 1
        m = (N/k) - 1
        if m <= 0: continue
        if N//m == N%m:
            ans += m
    print(int(ans))


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n = int(input())
  
flag = True
a = 1
m = 0
while flag:
        if n-a <= a**2:
                flag = False
        else:
                if (n-a) % a == 0:
                        m += (n-a) // a
        a += 1

print(m)

Submission status: Accepted

Solution code:
import math
ans=0
n=int(input())
yakusu=[]
for num in range(1,math.floor(math.sqrt(n))+1):
    if n%num==0:
        yakusu.append(num)
        if n//num>num:
            yakusu.append(n//num)
# print(yakusu)
for k in yakusu:
    m=n//k-1
    if m>k:
        ans+=m
print(ans)

Submission status: Accepted

Solution code:
N = int(raw_input())

sq = int((N+1)**0.5)

s = 0
for i in xrange(1, sq):
    if N % i == 0:
        s += (N/i) - 1
        
print s

Submission status: Accepted

Solution code:
def divisor(n):
    A = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            if n//i == i:
                A.append(i)
            else:
                A.append(i)
                A.append(n//i)
    A = [a for a in A if a > 2]
    return A

n = int(input())
A = divisor(n)
ans = 0
for a in A:
    i,j = divmod(n,a-1)
    if i == j:
        ans += a-1
print(ans)

Submission status: Accepted

Solution code:
import math

N = int(input())

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

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

print(ans)

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


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

Submission status: Accepted

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

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

Submission status: Accepted

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

    for i in range(max_len[depth]+1):
        yield from comb(val+[i], max_len, depth+1)
# for it in comb(val, max_len):
# #     print('a')
#     print(it)


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

divisor = primeFactor(N)


ans = 0
val = []
for it in comb(val, list(divisor.values())):
    total = 1
    for i, j in zip(list(divisor.keys()), it):
    #     print(i, j)
        total *= i**j
#     print(total)
    
    m = total - 1
    if m < 1:
        continue
    if N%m==N//m:
#         print('{0} mod {1} = {2}, {0}/{1} = {3}'.format(N, m, N%m, N//m))
        ans += m
        
print(ans)

Submission status: Accepted

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

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

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