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 sys

# import re
import math
import collections
# import decimal
import bisect
# import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()

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


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)

    # divisors.sort()
    return divisors
#print(make_divisors(n))
li = make_divisors(n)
ans = 0
for l in li:
    if l == 1:
        continue
    t = l - 1
    if n % t == n//t:
        ans += t
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import *
import heapq
import math

import bisect
import copy
from itertools import permutations,accumulate,combinations,product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())

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

Submission status: Accepted

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
n = int(input())
l = make_divisors(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:
n = int(input())

import math
rt = math.floor(math.sqrt(n))
result = 0
for i in range(1,rt + 1):
  if n % i == 0 and i**2 != n:
    if n % (n / i - 1) != 0:
      result += n / i - 1
print(int(result))

Submission status: Accepted

Solution code:
import math
N = int(input())
ans = 0
for m in range(1,math.ceil(N**(1/2))):
  if (N-m)%m == 0 and m < (N-m)//m:
    ans += int((N-m)/m)

if N == 1:
  ans = 0
if N == 2:
  ans = 0
if N == 3:
  ans = 2
if N == 6:
  ans = 5
print(ans)

Submission status: Accepted

Solution code:
# N//m=N%m
# (N-N%m)/m=N%m
# N=(N%m)(m+1)

n=int(input())

def make_divisor(x):
    ret=[]
    for i in range(1,int(x**.5)+1):
        q,m=divmod(x,i)
        if m==0:
            ret.append(i)
            if i==q:continue
            ret.append(q)
    return ret

ans=[]
d=make_divisor(n)

for e in d:
    if e==1:continue
    m=e-1
    k=n%m
    if k*e==n:
        ans.append(m)
print(sum(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    import time
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N = int(input())
    mod = N
    ans = 0
    c = 1
    while True:
        if N // mod == N % mod:
            ans += mod
            c += 1
            mod = N // c
            continue
        mod -= 1
        if not mod:
            break
        if N % mod > c:
            c += 1
            mod = N // c
            continue
        if N // mod == N // c:
            c += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

sys.setrecursionlimit(10 ** 7)

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()

def add(m):
    m -= 1
    if m and n % m == n // m:
        return m
    return 0

i = 1
ans = 0
while i * i <= n:
    ans += add(i)
    if i * i != n:
        ans += add(n // i)
    i += 1
    
print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d

n = int(input())

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

Submission status: Accepted

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

    i = 1
    out = 0
    while i*i <= N:
        if N%i == 0 and i < N//i-1:
            out += (N//i - 1)
        i += 1
    print(out)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    n=int(input())
    ans=0
    div_n=make_divisors(n)
    for p in div_n:
        m=(n-p)//p
        if m>0 and n%m==p:
            ans+=m
    print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
import math
ans = 0
for k in range(1, int(math.sqrt(N) + 1)):
    # print(k - 1, N // k - 1)
    m = N // k - 1
    if m != 0:
        if N % k == 0 and 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)+2):
    if n%i == 0 and n//i>=i+2:
        ans += (n//i)-1
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def calc_divisors(n):
    divisors_a = []
    divisors_b = []
    for d in range(1, int(n**0.5) + 1):
        if n % d == 0:
            divisors_a.append(d)
            if n // d != d:
                divisors_b.append(n // d)
    divisors = divisors_a + divisors_b[::-1]
    return divisors


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

    divisors = calc_divisors(N)
    ans = 0
    for divisor in divisors:
        q = divisor
        m = N // q - 1
        if 1 < m and q < m:
            ans += m

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d

from math import ceil, floor

def divisors(N):
    ans = []
    i = 1
    while i * i <= N:
        if N % i == 0:
            ans.append(i)
            if N // i != i:
                ans.append(N // i)
        i += 1
    ans.sort()
    return ans

N = int(input())
fN = divisors(N)

total = 0
for m in fN[1:]:
    m -= 1
    if floor(N / m) == N % m:
        total += m
print(total)

Submission status: Accepted

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

    divisors.sort()
    return divisors
n=int(input())
div=make_divisors(n)
# print(div)
ans=0
for i in range(len(div)):
  m=div[i]
  m=n//div[i]-1
  if m!=0:
    if n//m==n%m:
      ans+=m
print(ans)

Submission status: Accepted

Solution code:
import math
x = int(input())
if x == 1:
  print(0)
  exit()
  
d = math.ceil((x+1)**0.5)
def divisorize(fct):
    b, e = fct.pop()
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]
 
 
def factorize(n):
    fct = []
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
 
 
def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

ans = 0
fct = factorize(x)
for div in divisorize(fct):
    c = num(div)
    if d+1 <= c:
      ans += c-1
      
print(ans)

Submission status: Accepted

Solution code:
import math
x = int(input())
if x == 1:
  print(0)
  exit()
  
d = math.ceil((x+1)**0.5)
def divisorize(fct):
    b, e = fct.pop()
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]
 
 
def factorize(n):
    fct = []
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
 
 
def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

ans = 0
fct = factorize(x)
for div in divisorize(fct):
    c = num(div)
    if d+1 <= c:
      ans += c-1
      
print(ans)

Submission status: Accepted

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


def calc_divisors(n):
    divisors_a = []
    divisors_b = []
    for d in range(1, int(n**0.5) + 1):
        if n % d == 0:
            divisors_a.append(d)
            if n // d != d:
                divisors_b.append(n // d)
    divisors = divisors_a + divisors_b[::-1]
    return divisors


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

    divisors = calc_divisors(N)

    # N = qm + r
    #   q = r
    # --> N = rm + r = r(m+1) (r < m)

    m_set = set()
    for d in divisors:
        m = N // d - 1
        if d < m and m != 1:
            m_set.add(m)
    ans = sum(m_set)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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


def resolve():
    n = int(input())

    div = make_divisors(n)
    res = 0
    for i in div:
        if i != 1:
            x, y = divmod(n, i - 1)
            if x == y:
                res += i - 1

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

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


n=int(input())
A=make_divisors(n)

ans=0
for m in A[1:]:
    m -=1
    if int(n/m)==n%m:
        ans +=m
print(ans)

Submission status: Accepted

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


n=int(input())
A=make_divisors(n)

ans=0
for m in A[1:]:
    m -=1
    if int(n/m)==n%m:
        ans +=m
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    N=int(input())
    cnt=0
    i=1
    while True:
        M=N
        M-=i
        p=M/i
        if p<=i:
            break
        else:
            if p.is_integer():
                cnt+=p
            i+=1
    print(int(cnt))



resolve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())

def divisors(n):
    ret = set()
    m = 1
    while m*m <= n:
        if n%m==0:
            # ret.add(m)
            if n//m > m+1:
                ret.add(n//m)
        m += 1
    return ret
ndivs = list(divisors(n))

ans = sum(ndivs) - len(ndivs)*1

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
ans=0
#約分
def make_divisors(n):  
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors
l=make_divisors(n)
for li in l:
  m=(n-li)//li
  if li <= m-1:
    ans+=m
print(ans)

Submission status: Accepted

Solution code:
# Problem D - DivRem Number

# input
N = int(input())

# initialization
ans = 0

# count
r = 1
while r**2<=N:
    if (N-r)%r==0 and (N-r)/r>r:
        ans += (N-r)//r
    r += 1

# output
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

    divisors.sort()
    return divisors

divisors = make_divisors(N)

i = 0
res = 0
while True:
    l = divisors[i]
    r = divisors[-(i+1)]
    if r - 1 > l:
        res += r - 1
        i += 1
    else:
        break

print(res)

Submission status: Accepted

Solution code:
import math
N=int(input())
ans=[]
for i in range(1,int(math.sqrt(N))+1):
    if N%i==0:
        num1=i
        num2=N//i
        if (num1-1)>num2:
            ans.append(num1-1)
        if (num2-1)>num1:
            ans.append(num2-1)
#print(ans)
ans=list(set(ans))
print(sum(ans))

Submission status: Accepted

Solution code:
from math import sqrt
N = int(input())
M = int((sqrt(4*N+1)-1)/2)
ans = 0
a = 1
while a <= M:
  if N % a == 0:
    m = N // a - 1
    ans += m if m > 0 and N % m == a else 0
  a += 1
print(ans)

Submission status: Accepted

Solution code:
N = int(input())

# Nの因数を昇順で返す関数。1含む
def factor(n):
    f = []
    for i in range(1, int(n**0.5) + 1):
        if n%i == 0:
            f.append(i)
            if i != n//i:
                f.append(n//i)
    return f

ans = 0
for x in factor(N):
    m = (N//x) - 1
    if x < m:
        ans += m

print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())

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

div = make_divisors(n)
ans = 0
for i in div:
    res = n//i-1
    if res <= 0:continue
    if n%res==i:
        ans += res

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(reverse=True)
    return divisors

d = make_divisors(n)
ans = 0
for a in d:
    if a == 1:
        continue
    else:
        q = n//a
        m = a-1
        if 0 <= q <= m-1:
            ans += m
print(ans)

Submission status: Accepted

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

    divisors.sort()
    return divisors

a = md(n)

ans = 0
for i in a:
    b = n // i
    if i < b-1:
        ans += (b-1)
        
print(ans)

Submission status: Accepted

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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

    # divisors.sort()
    return divisors


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


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

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

    print(res)


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

l=make_divisors(N)
ans=0
for i in range(len(l)):
    num=l[i]-1
    if num==0:
        continue
    if num==1:
        continue
    p=N//num
    q=N%num
    if p==q:
        ans+=num 
print(ans)

Submission status: Accepted

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

    N = int(input())
    divs = trial_division(N)
    ans = 0
    for d in divs:
        if d != 1 and N//(d-1) == N % (d-1):
            ans += (d-1)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


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


def solve():
    N = int(rl())
    
    divs = make_divisors(N)
    ans = 0
    for div in divs[1:]:
        m = div - 1
        if N // m == N % m:
            ans += m
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import numpy as np
import math

N = int(input())


lim = math.ceil(np.sqrt(N))

ans = 0

for i in range(lim):
    rem = i+1
    if N <= rem**2 + rem:
        break
    if (N-rem) % rem == 0:
        ans += (N-rem)/rem

print(int(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
l=make_divisors(n)
ans=0
for i in l:
    if i-1>(n**0.5):
        ans+=i-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 == 0:
        a = n//i - 1
        b = i - 1
        #print("{} {}".format(b,a))
        if a != 0 and (n // a) == n % a:
            ans += a
        if b != 0 and (n // b) == n % b:
            ans += b
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
import math


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

nums = make_divisors(N)
# print(nums)
ans = 0
for num in nums:
    if num != 1:
        if N % (num -1) == N // (num -1):
            ans += num -1
print(ans)
# for m in range(1,N + 1):
#     ans = 0
#     if N//m == N % m:
#         print("SAME")
#         print(f"{m}: 商:{N//m} 余り:{N % m}")
#         print("SAME")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

print(solve())

Submission status: Accepted

Solution code:
MOD = 10 ** 9 + 7
INF = 10 ** 12
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  itertools import permutations
from heapq import heapify,heappop,heappush

def main():
    n = int(input())
    ans = 0
    for i in range(1,n):
        if i * i > n:
            break
        if n%i == 0:
            j = n//i
            if j - 1 > i:
                ans += j - 1
    print(ans)
    
if __name__ =='__main__':
    main()

Submission status: Accepted

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

ans = 0
for Q in range(1, math.floor(math.sqrt(N)) + 1):
    if N % Q == 0:
        if Q <= N // Q - 2:
            ans += N // Q - 1
            # print(k - 1)
print(ans)

Submission status: Accepted

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

def partions(M):#Mの約数列 O(n^(0.5+e))
    import math
    d=[]
    i=1
    while math.sqrt(M)>=i:
        if M%i==0:
            d.append(i)
            if i**2!=M:
                d.append(M//i)
        i=i+1
    d.sort()
    return d

list=partions(N)
for i in range(0,len(list)//2):
    q=list[i]
    m=N//list[i]-1
    if m>q:
        ans+=m

print(ans)

Submission status: Accepted

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

    # divisors.sort()
    return divisors

n = int(input())
count = 0
for i in make_divisors(n):
    if i == 1:
        continue
    quotient, remainder = divmod(n, i-1)
    if quotient == remainder:
        count += i-1

print(count)

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 = N//i - 1
        if x > i:
            ans += x

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

result = 0
for i in range(1, int(n**(1/2)+1)):
    if n%i==0:
        x = n//i -1
        if x > i:
            result += x
print(result)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/diverta2019/tasks/diverta2019_d
# 問題文を数式に起こすと N=am+a (a<m, a \in N)を満たすmの合計を求めろという問題
# N=a(m+1) なのでN%(m+1)=0になるmの中で条件を満たすものを合計すれば良い。つまりNの約数を列挙する。
# 約数は√Nまで調べればいいので、オーダーはO(√N)となる


def make_divisors(n: int, sort=False):
    # 約数列挙
    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)
    if sort:
        divisors.sort()
    return divisors


N = int(input())
candi = make_divisors(N)
ans = 0
for mp in candi:
    m = mp - 1
    if m > 0 and (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**(1/2))+10):
  if (n-i)%i==0 and (n-i)//i>i:
    ans=ans+(n-i)//i
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
div = []
ans = 0
for i in range(1,int(pow(N,0.5)+3)):
    if N%i==0:
        div.append(i)
        div.append(N//i)
div = list(set(div))
for i in map(lambda x:x-1,div):
    if i != 0 and N%i==N//i:
        ans += i
print(ans)

Submission status: Accepted

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

total = 0
for i in range(ceil(n ** 0.5) + 1):
  if n % (i + 1) == 0:
    a = n // (i + 1) - 1
    if a >= 2 and n // a == n % a:
      total += a

print(total)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
p = 1
while True:
    if p ** 2 >= n:
        break
    if (n - p) % p == 0 and n % ((n - p) // p) != 0:
        ans += (n - p) // p
    p += 1

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

# 約数列挙(1,N)も含まれる
prime, i = set(), 1
while i * i <= N:
    if N % i == 0:
        prime.add(i)
        prime.add(N//i)
    i += 1

#print(prime)
ans = []
for i in prime:
    if i == 1:
        continue
    i -= 1
    if N // i == N % i:
        ans.append(i)

print(sum(ans))

Submission status: Accepted

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

for i in range(1, N):
    if i * i > N:
        break
    elif i * i == N:
        rem.append(i)
    elif N % i == 0:
        rem.extend([i, N // i])

ans = 0
for r in rem:
    if (r - 1) > N // r:
        ans += r - 1
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import floor


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(readline())
prime_list = make_divisors(n)
ans = 0
prime_list.remove(1)
for i in range(len(prime_list)):
    prime_list[i] -= 1
    if floor(n / prime_list[i]) == n % prime_list[i]:
        ans += prime_list[i]
print(ans)

Submission status: Accepted

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


N = int(input())
d = make_divisors(N)
ans = 0
for i in d:
    a = i-1
    m = N//i
    if a > m:
        ans += a

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    s = int(sqrt(n)) + 1
    ans = 0
    for i in range(1, s+1):
        x = n - i
        m = x // i
        if m > i and x % i == 0 :
            ans += m
    print(ans)

    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())

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)

ans = 0
for i in l:
    m = (N//i)-1
    if m:
        a, b = divmod(N, m)
        if a==b:
            ans += m

print(ans)

Submission status: Accepted

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

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

    def yakusu():
        for i in range(1, int(n**0.5)+1):
            if n%i == 0:
                yield i
                if i != n //i:
                    yield n//i

    for m in yakusu():
        m -= 1
        if m == 0:
            continue

        if n // m == n % m:
            yield m

print(sum(main()))

Submission status: Accepted

Solution code:
N = int(input())

ans = 0
for i in range(1,10**6):
    mm = (N-i)//i
    if mm!=0 and N%mm == N//mm:
        # print(i,mm)
        ans += mm
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

'''
x / y = a ... b -> ay * b = x を今回の問題に当てはめ,N//m = N mod m = kとすると
km + k = N -> N = k(m + 1)となり
k と m + 1 はNの約数となる
また、N mod m < mより
k < mとなり
k < N ** 0.5 
'''
ans = 0
for i in range(1, int(n**.5)+1):
    if n % i or i >= n // i - 1:
        continue
    ans += n // i - 1
print(ans)

Submission status: Accepted

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

N = int(input())
yaku = yakusu(N)
ans = 0
for i in yaku:
    if i == 1: continue
    v, n = divmod(N, i - 1)
    if v == n:
        ans += (i - 1)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

ans = 0

a = 1
while a**2 < n and a*(a+1) < n:
    if n % a == 0:
        ans += n//a - 1
    a += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
if n==2:
    print(0)
    exit()
ans=n-1
for i in range(int(n**0.5)+1,2,-1):
    # print(n//i+1)
    l,r=n//i+1,n//(i-1)+1
    while l+1<r:
        mid=(l+r)//2
        if n//mid<=n%mid:
            l=mid
        else:
            r=mid
    if n//l==n%l:
        ans+=l
print(ans)