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: Wrong Answer

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


def solve(N: int):
    ret = 0
    i = 1
    used = set()
    while i * i <= N:
        tmp = N - i
        if tmp % i == 0:
            val = tmp // i
            if not val in used:
                ret += val
                used.add(val)
        if N % (i + 1):
            val2 = N // (i + 1) != i
            #if val2 != val:
            if not val2 in used:
                ret += val2
                used.add(val2)
        i += 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#D
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
div = sorted(make_divisors(N))[::-1]
if len(div) % 2 == 0:
    div =  div[:int(len(div)/2)]
else:
    div = div[:len(div)//2]

print(sum(div)-len(div))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(s)

Submission status: Wrong Answer

Solution code:
import math


def main():
    N = int(input())
    sqrt = math.ceil(math.sqrt(N))
    ans = 0
    for x in range(1, sqrt):
        if N % x == 0:
            y = N // x - 1
            ans += y
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())

lim = int((n**0.5))

ans = 0
for i in range(1,lim+1):
    if n%i == 0 and i*i != n:
        ans += (n//i)-1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if n == 1:
    print(1)
    exit()


for i in range(1, int(n**0.5)+1):
    n2 = n - i
    if n2 % i == 0:
        #print(n2+i , n/(n2/i), i)
        try:
            if abs(n/(n2/i) - i) < 1:
                ans += math.ceil(n2 / i)
        except:
                ans += math.ceil(n2 / i)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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)
b = []
for i in range(len(a)):
  k = a[i]
  if k > N**0.5:
    b.append(k)
#print(a)
print(sum(b)-len(b))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:


def main():
    n = input()
    if n == 2:
        print 0
        return
    s = 0
    i = 1
    while i * (i + 1) <= n:
        if (n - i) % i == 0:
            s += (n - i) // i
        i += 1
    print s


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
n_1 = int(n ** (1/2))
s = 0
 
for i in range(1,n_1):
    if n % i == 0:
        s += (n // i) - 1

print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n == 1:
    print(1)
    exit()


for i in range(1, int(n**0.5)+2):
    n2 = n - i
    if n2 % i == 0:
        #print(n2+i , n/(n2/i), i)
        try:
            if abs(n/(n2/i) - i) < 1:
                ans += math.ceil(n2 / i)
        except:
            pass
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
cnt = 0
for i in range(1, int(np.sqrt(N))+1):
    cnt += (N-i)//i
print(cnt)

Submission status: Wrong Answer

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

if n == 1:
    print(1)
    exit()


for i in range(1, int(n**0.5)):
    n2 = n - i
    if n2 % i == 0:
        #print(n2+i , n/(n2/i), i)
        try:
            if abs(n/(n2/i) - i) < 1:
                ans += math.ceil(n2 / i)
        except:
            pass
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
AtCoder D
"""

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = int(input()) for _ in range(N) # 1 row N column

# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']

def main():
    # A, B = list(map(int,input().split()))
    N = int(input())
    tmp=0
    i=1
    N2=max(N,2000000)
    while i<N2:
        print(i,(N-i))
        mod=(N-i)%i
        if mod==0:
           tmp+=(N-i)/i
        i+=1
    print(int(tmp))
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)

def divisions(n):
    sq = int(math.sqrt(n)+1)
    ss = 30030
    a = [None] * (ss)
    a[0] = 1
    t = 1
    for i in range(2,ss):
        if not a[i] is None:
            continue
        if t * i > ss:
            break
        t *= i
        for j in range(i*2,ss,i):
            a[j] = 1
    a = [i for i in range(t) if a[i] is None]
    d = collections.defaultdict(int)
    for i in a[1:]:
        while n % i == 0:
            n //= i
            d[i] += 1

    for j in range(1,sq//t+2):
        if j > n:
            break
        for ii in a:
            i = t*j+ii
            while n % i == 0:
                n //= i
                d[i] += 1
    r = [1]
    for k, v in d.items():
        for c in r[:]:
            for i in range(1,v+1):
                r.append(c*(k**i))

    return sorted(r)

def main():
    n = I()
    ds = divisions(n)
    # print(ds)
    r = 0
    u = set([0])
    mk = ds[0]
    if len(ds) > 1:
        mk = ds[1]
    for k in ds:
        if k < 2:
            continue
        for a in range(1,mk):
            t = k - a
            if t in u:
                continue
            u.add(t)
            if n // t == n % t:
                r += t

    return r


print(main())

Submission status: Wrong Answer

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

if n == 1:
    print(1)
    exit()


for i in range(1, int(n**0.5)+1):
    n2 = n - i
    if n2 % i == 0:
        #print(n2+i , n/(n2/i), i)
        try:
            if abs(n/(n2/i) - i) < 1:
                ans += math.ceil(n2 / i)
        except:
            pass
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
i=1
a=[]
while i*i<n:
    if n%i ==0:
        a.append(n//i)
    i+=1
print(sum(a)-len(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ans = 0
for i in range(1, int(n**0.5)+1):
    n2 = n - i
    if n2 % i == 0:
        #print(n2+i , n/(n2/i), i)
        try:
            if abs(n/(n2/i) - i) < 0.98:
                ans += math.ceil(n2 / i)
        except:
            print(1)
            exit()
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
n_1 = int(n ** (1/2)) + 1
s = 0

for i in range(1,n_1 + 1):
    if n % i == 0:
        s += (n // i) - 1

print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
if N % 2 == 0:
  print(N // 2 - 1 + N - 1)
else:
  print(N - 1)

Submission status: Wrong Answer

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

ans = 0
for i in range(1, math.ceil(N**(1/2))):
    if N % i == 0:
        ans += N//i - 1

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
ans = 0
for i in range(1, int(n**0.5)+1):
    n2 = n - i
    if n2 % i == 0:
        #print(n2+i , n/(n2/i), i)
        try:
            if abs(n/(n2/i) - i) < 0.95:
                ans += math.ceil(n2 / i)
        except:
            pass

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
if N % 2 == 0:
  print((N // 2 - 1) * 2 + (N - 1) * 2)
else:
  print((N - 1) * 2)

Submission status: Wrong Answer

Solution code:
1000000000000

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)

def divisions(n):
    sq = int(math.sqrt(n)+1)
    ss = 30030
    a = [None] * (ss)
    a[0] = 1
    t = 1
    for i in range(2,ss):
        if not a[i] is None:
            continue
        if t * i > ss:
            break
        t *= i
        for j in range(i*2,ss,i):
            a[j] = 1
    a = [i for i in range(t) if a[i] is None]
    d = collections.defaultdict(int)
    for i in a[1:]:
        while n % i == 0:
            n //= i
            d[i] += 1

    for j in range(1,sq//t+2):
        if j > n:
            break
        for ii in a:
            i = t*j+ii
            while n % i == 0:
                n //= i
                d[i] += 1
    r = [1]
    for k, v in d.items():
        for c in r[:]:
            for i in range(1,v+1):
                r.append(c*(k**i))

    return r

def main():
    n = I()
    ds = divisions(n)
    # print(ds)
    r = 0
    for k in ds:
        if k < 2:
            continue
        t = k - 1
        if n // t == n % t:
            r += t

    return r


print(main())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


def solve(N: int):
    res = 0
    x = 1
    while x * x <= N:
        mp1, r = divmod(N, x)
        x += 1
        if r > 0:
            continue
        m = mp1 - 1
        if x >= m:
            break
        res += m
    print(res)
    return


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

Solution code:
from itertools import combinations
from functools import reduce
from operator import mul
N = int(input())


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


A = factorization(N)
l = []
for a in A:
    l += [a[0]] * a[1]

ans = 0
for i in range(1, len(l)+1):
    for s in set(combinations(l, i)):
        r = reduce(mul, s) - 1
        if r == 0:
            continue
        if N // r == N % r:
            ans += r

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())


from math import floor
total=0
for m in range(1,n):
    if floor(n/m)==n%m:
        total+=m

print(total)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ans = 0
for i in range(1,N):
    if N % i == 0:
        temp = N // i - 1
        d,m = divmod(N,temp)
        if d != m:
            break
        else:
            ans += temp
print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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())
# N = 1000000
fN = divisors(N)
total = 0
for i in range(len(fN) - 1):
    if fN[i + 1] - fN[i] == 1:
        continue
    mp = N // fN[i]
    mpp = N // fN[i + 1]
    # print(fN[i], fN[i + 1], " | [{},{}]".format(mpp, mp))
    for mm in range(mpp, mp):
        for rr in range(1, fN[i] + 1):
            # print(N - rr, floor((N - rr) / mm) == ceil((N - rr) / mm) and rr == mm)
            if floor((N - rr) / mm) == ceil((N - rr) / mm) and rr == mm:
                # print(rr, mm)
                total += (N - rr) // mm
            # print(mm, rr, floor((N - rr) / mm))
print(total)
    
# print()
# total2 = 0
# for m in range(1, N + 1):
#     f1 = floor(N / m)
#     f2 = N % m
#     if f1 == f2:
#         print(m, f1, f2, f1 == f2)
#         total2 += m
# print(total2)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
point = 0
for i in range(1,n+1):
    if n%i == n//i:
        point += i
print(point)

Submission status: Time Limit Exceeded

Solution code:
from math import sqrt
N = int(input())
ans = 0
# if N // i = p, N % i = p, 
# N = pi + p = p(i+1)
# p < sqrt(N) and p < i 
for p in range(1,N):
  if N % p > 0:
    continue
  i = N//p - 1
  if p >= i:
    break
  ans += i
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:

import math

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

Submission status: Time Limit Exceeded

Solution code:
#Nに対して, N=m*q+m を求める
#
#8=3*2+2
# =7*1+1
#N=m*q+q=q(m+1)
#「mで割ったあまり」はm以上になってはいけない
#q<m<m+1ゆえ, 
#q<sqrt(N)になる, ただし十分ではない
#
#8; 1,2,4,8 -> 0,1,[3,7]
#           q= 8,4
# 1<=q<mなので, 1<=N/(m+1)<m
# m<=N-1 and N<m(m+1) m^2+m-N>0  <-> (m+1/2)^2>N+1/4
# m+1/2<-sqrt(N+1/4) or m+1/2>sqrt(N+1/4)  
# -1/2+sqrt(N+1/4)<m<N
import math

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

Submission status: Time Limit Exceeded

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


def solve(N: int):

    res = 0
    for i in range(1,N):
        a = (N-i) % i 
        b = (N-i) // i 

        if a == 0:
            if b > i:
                res += b
            else:
                break

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
y = [i-1 for i in range(2,N+1) if N % i == 0 and N//(i-1) == N % (i-1)]

print(sum(y))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
y = [i-1 for i in range(2,N+1) if N % i == 0]
n = 0
for i in y:
	q, mod = divmod(N, i)
	if q == mod:
		n += i

print(n)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
y = []
for i in range(2,N+1):
	if N % i == 0:
		q, mod = divmod(N, i-1)
		if q == mod:
			y.append(i-1)

print(sum(y))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import defaultdict
from itertools import product
from functools import reduce 
from operator import mul


def is_prime(num):
    if not isinstance(num, int):
        return False
    if num <= 1:
        return False
    if num == 2 or num == 3:
        return True
    if num % 6 in [0, 2, 3, 4]:
        return False
    div_max = int(math.sqrt(num))
    for div in range(5, div_max + 1, 2):
        if num % div == 0:
            return False
    return True

def factorint(x):
    factors = defaultdict(int)
    while not is_prime(x):
        div_max = int(math.sqrt(x))
        for div in range(2, div_max + 1):
            if x % div == 0:
                factors[div] += 1
                x = int(x / div)
                break
    factors[x] += 1
    return factors

ans = 0
n = int(input())
if n==0:
    print(0)
    exit()
rn = math.sqrt(n+1) + 1
factor_dict = factorint(n)
ks = [range(k+1) for k in factor_dict.values()]
prs = product(*ks)
for pr in prs:
    s = reduce(mul, [factor**p for factor,p in zip(factor_dict.keys(), pr)])
    if s >= rn:
        ans += s -1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import defaultdict
from itertools import product
from functools import reduce 
from operator import mul


def is_prime(num):
    if not isinstance(num, int):
        return False
    if num <= 1:
        return False
    if num == 2 or num == 3:
        return True
    if num % 6 in [0, 2, 3, 4]:
        return False
    div_max = int(math.sqrt(num))
    for div in range(5, div_max + 1, 2):
        if num % div == 0:
            return False
    return True

def factorint(x):
    factors = defaultdict(int)
    while not is_prime(x):
        div_max = int(math.sqrt(x))
        for div in range(2, div_max + 1):
            if x % div == 0:
                factors[div] += 1
                x = int(x / div)
                break
    factors[x] += 1
    return factors

ans = 0
n = int(input())
rn = math.sqrt(n+1) + 1
factor_dict = factorint(n)
ks = [range(k+1) for k in factor_dict.values()]
prs = product(*ks)
for pr in prs:
    s = reduce(mul, [factor**p for factor,p in zip(factor_dict.keys(), pr)])
    if s >= rn:
        ans += s -1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

ans = 0
x = 1

while 1:
    if n % x == 0:
        m = n // x - 1
        if m <= x:
            break
        else:
            ans += m
    x += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

ans = 0
x = 1

while x < n:
    if n % x == 0:
        m = n // x - 1
        if m <= x:
            break
        else:
            ans += m
    x += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    ans = 0
    for m in range(1, N+1):
        if N % (m + 1) != 0:
            continue
        elif N // (m + 1) < m:
            ans += m
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

import sys
from math import sqrt

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()

# for i in range(N, 0, -1):
#     print(i, N//i, N%i)

m=N
ans=set()
while m>=sqrt(N):
    i=N//m
    while m>0:
        if i==N%m:
            ans.add(m)
            break
        elif i<N%m:
            break
        else:
            m-=1
    m=N//(i+1)

for m in range(1, int(sqrt(N))+1):
    if N//m==N%m:
        ans.add(m)

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())


suma=0
for m in range(1,N):
    if N//m==N%m:
        suma+=m    

print(suma)

Submission status: Time Limit Exceeded

Solution code:
def get_factors(n: int) -> list:
    factors = []
    div = 2
    while n != 1:
        if n % div == 0:
            n //= div
            factors.append(div)
        else:
            div += 1
    factors_dict = {f: factors.count(f) for f in factors}
    return [[f**exp for exp in range(count + 1)]
            for f, count in factors_dict.items()]


from itertools import product
from functools import reduce
N = int(input())
factors = get_factors(N)
ans = 0
for elements in product(*factors):
    factor = reduce(lambda acc, n: acc * n, elements, 1)
    div = factor - 1
    if div > 0 and N // div == N % div:
        ans += div
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def get_prime_factors(n: int) -> list:
    factors = []
    div = 2
    while n != 1:
        if n % div == 0:
            n //= div
            factors.append(div)
        else:
            div += 1
    return factors


def make_factors(prime_factors: list, factors: set, n=1, i=0):
    if i < len(prime_factors):
        factors.add(n * prime_factors[i])
        make_factors(prime_factors, factors, n, i + 1)
        make_factors(prime_factors, factors, n * prime_factors[i], i + 1)
    else:
        return


from itertools import combinations
N = int(input())
prime_factors = get_prime_factors(N)
factors = {1}
make_factors(prime_factors, factors)
ans = 0
for div in (f - 1 for f in factors if f > 1):
    ans += div if N // div == N % div else 0
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from itertools import product

n = int(input())
if n < 3:
    print(0)
else:
    rt = int(n ** 0.5)
    factors = defaultdict(int)
    N = n
    n_div = 2
    while n > 1:
        while not n % n_div:
            factors[n_div] += 1
            n = n // n_div
        n_div += 1
        if (n_div == rt+ 2) and (n == N):
          factors[N] += 1
          break
    lis = [1]
    for k, v in factors.items():
        facts = [k ** i for i in range(v + 1)]
        it = product(lis, facts)
        lis = [a * b for a, b in it]
    nums = [l - 1 for l in lis if l - 1]
    nums = [i for i in nums if (N //i) == (N % i)]
    print(sum(nums))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from itertools import product

n = int(input())
if n < 3:
    print(0)
else:
    rt = int(n ** 0.5)
    if n // rt != rt:
        rt = 0
    factors = defaultdict(int)
    N = n
    n_div = 2
    while n > 1:
        while not n % n_div:
            factors[n_div] += 1
            n = n // n_div
        n_div += 1
        if n == int(n ** 0.5) + 1:
          factors[N] += 1
          break
    lis = [1]
    for k, v in factors.items():
        facts = [k ** i for i in range(v + 1)]
        it = product(lis, facts)
        lis = [a * b for a, b in it]
    nums = [l - 1 for l in lis if l - 1]
    nums = [i for i in nums if (N //i) == (N % i)]
    print(sum(nums))