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: Runtime Error

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


class Prime:
    # https://qiita.com/daikw/items/f48d6ac374255763463d
    seed_primes = [
        2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
        71, 73, 79, 83, 89, 97
    ]

    def is_prime(self, n):
        """
        prime test (hybrid)

        see also: https://qiita.com/gushwell/items/ff9ed83ba55350aaa369

        :param n:
        :return: boolean
        """
        is_prime_common = self.is_prime_common(n)
        if is_prime_common is not None:
            return is_prime_common

        if n < 2000000:
            return self.is_prime_brute_force(n)
        else:
            return self.is_prime_miller_rabin(n)

    def is_prime_common(self, n):
        if n == 1: return False
        if n in Prime.seed_primes: return True
        if any(map(lambda x: n % x == 0, self.seed_primes)): return False

    def is_prime_brute_force(self, n):
        """
        brute force prime test
        use with is_prime_common if you want to skip seed_primes

        :param n:
        :return: boolean
        """
        for k in range(2, int(math.sqrt(n)) + 1):
            if n % k == 0:
                return False
        return True

    def is_prime_miller_rabin(self, n):
        """
        miller rabin prime test
        use with is_prime_common if you want to skip seed_primes

        see also
            algorithm: https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
            implementation: https://qiita.com/srtk86/items/609737d50c9ef5f5dc59
            improvement: https://qiita.com/gushwell/items/ff9ed83ba55350aaa369

        :param n:
        :return: boolean
        """

        d = n - 1
        while d & 1 == 0:
            d >>= 1

        # use one of these lines / upper is more efficient.
        witnesses = self.get_witnesses(n)
        # witnesses = [random.randint(1, n - 1) for _ in range(100)]

        for w in witnesses:
            y = pow(w, d, n)

            while d != n - 1 and y != 1 and y != n - 1:
                y = (y * y) % n
                d <<= 1

            if y != n - 1 and d & 1 == 0:
                return False

        return True

    def get_witnesses(self, num):
        def _get_range(num):
            if num < 2047:
                return 1
            if num < 1373653:
                return 2
            if num < 25326001:
                return 3
            if num < 3215031751:
                return 4
            if num < 2152302898747:
                return 5
            if num < 3474749660383:
                return 6
            if num < 341550071728321:
                return 7
            if num < 3825123056546413051:
                return 9
            return 12

        return self.seed_primes[:_get_range(num)]

    def gcd(self, a, b):
        if a < b:
            return self.gcd(b, a)
        if b == 0:
            return a
        while b:
            a, b = b, a % b
        return a

    @staticmethod
    def f(x, n, seed):
        """
        pseudo prime generator
        :param x:
        :param n:
        :param seed:
        :return: pseudo prime
        """
        p = Prime.seed_primes[seed % len(Prime.seed_primes)]
        return (p * x + seed) % n

    def find_factor(self, n, seed=1):
        """
        find one of factor of n
        this function is based to Pollard's rho algorithm

        see also
            algorithm: https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm
            implementation: https://qiita.com/gushwell/items/561afde2e00bf3380c98

        :param n:
        :param seed:
        :return: factor
        """
        if self.is_prime(n):
            return n

        x, y, d = 2, 2, 1
        count = 0
        while d == 1:
            count += 1
            x = self.f(x, n, seed)
            y = self.f(self.f(y, n, seed), n, seed)
            d = self.gcd(abs(x - y), n)

        if d == n:
            return self.find_factor(n, seed + 1)
        return self.find_factor(d)

    def find_factors(self, n):
        primes = {}
        if self.is_prime(n):
            primes[n] = 1
            return primes

        while n > 1:
            factor = self.find_factor(n)

            primes.setdefault(factor, 0)
            primes[factor] += 1

            n //= factor

        return primes


factors_dict = Prime().find_factors(N)
factors_values = list(factors_dict.values())
factors_keys = list(factors_dict.keys())
factors = []
import itertools
for K in itertools.product(*[range(_ + 1) for _ in factors_values]):
    f = 1
    for i in range(len(factors_keys)):
        f *= factors_keys[i]**K[i]
    factors += [f]
ans = 0
for f in factors:
    if N < f * (f - 1):
        ans += f - 1
print(ans)

Submission status: Runtime Error

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

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

print(result)

Submission status: Runtime Error

Solution code:
import sympy
import itertools

def hoge(i):
    ans = 1
    for j in i:
        ans *= j
    if(ans > 2):
        return ans - 1
    return 0

N = int(input())
facts = sympy.factorint(N)

for key in facts:
    for v in range(facts[key]):
        fact_list.append(key)
        
res = 0
for h in range(len(fact_list)+1):
    calced_set = set()
    iters = itertools.combinations(fact_list, h)
    for i in iters:
        if(i not in calced_set):
            res += hoge(i)
            calced_set.add(i)
print(res)

Submission status: Runtime Error

Solution code:

def solve(x):
    k=1
    s=0
    while True:
        if(x%k==0):
            i=(x//k)-1
            if (x//i==x%i):
                s+=i
        k+=1
        if k*k>x:
            break
    return s
        

x=int(input())
print(solve(x))

Submission status: Runtime Error

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

import sympy

N = int(input())
if N == 1 or N == 2:
    print("0")
    sys.exit()

N_divisors = sympy.divisors(N)

N_length = len(N_divisors)
N_length_half = N_length // 2
N_length_mod = N_length % 2

N_length_half_temp = 0

if N_length_mod == 1:
    N_length_half_temp = N_length_half + 1
else:
    N_length_half_temp = N_length_half

print(N_divisors)
print(sum(N_divisors[N_length_half_temp:]) - (N_length - N_length_half_temp))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import math
import bisect
INF = float("inf")


def solve(N: int):

    count = 0
    for r in range(1, int(math.sqrt(N))+1):  # 商
        # 余りは二分探索で良い
        lower = -(-N//r+1)
        upper = N//r
        while lower + 1 < upper:
            mid = (lower+upper)//2
            if N % mid >= r:
                lower = mid
            else:
                upper = mid
        if N % lower == r:
            count += lower
    print(count)

    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: Runtime Error

Solution code:
import numpy as np
def eratosthenes(n):
    is_prime = np.ones((n+1,), dtype=bool)
    is_prime[:2] = False
    for i in range(2,n+1):
        if is_prime[i]:
            is_prime[i*2::i]=False
    return np.arange(n+1)[is_prime]
Ps = eratosthenes(1000000)
def divisor(n):
    for p in Ps:
        if p*p>n:return -1
        if n%p==0:return p
def prime_division(n):
    d={}
    while n>1:
        p=divisor(n)
        if p==-1:d[n]=d.get(n,0)+1;break
        else:d[p]=d.get(p,0)+1;n//=p
    return d

def z(n,k,v):
    if len(k)==1:
        return [n*k[0]**i for i in range(v[0]+1)]
    else:
        r=[]
        for i in range(v[0]+1):
             r+=z(n*k[0]**i,k[1:],v[1:])
        return r
def y(n):
    pd=prime_division(n)
    KV=[[k,v] for k,v in pd.items()]
    K=[k for k,v in KV]; V=[v for k,v in KV]
    return z(1,K,V)

N=int(input())
r=0
#print(y(N))
for yakusu in y(N):
    if yakusu>N//yakusu and yakusu>1:
        r+=yakusu-1
print(r)

Submission status: Runtime Error

Solution code:
def sample_code():
    n = int(input())
    
    # print('# 素因数')
    fct = factorize(n)
    # print(fct, num(fct))
    answer = 0
    # print('# 約数')
    for div in divisorize(fct):
        if num(div) > n//num(div):
            answer += num(div) - 1
    print(answer)


def divisorize(fct):
    b, e = fct.pop()  # base, exponent
    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 = []  # prime factor
    b, e = 2, 0  # base, exponent
    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


if __name__ == '__main__':
    sample_code()

Submission status: Runtime Error

Solution code:
N=int(input())
if N==1 or N==2:
    print(0)
    quit()
def prime_factor(n):
    i = 2
    table = defaultdict(int)
    while i * i <= n:
        while n % i == 0:
            n //= i
            table[i]+=1
        i += 1
    if n > 1:
        table[n]+=1
    return table
table=prime_factor(N)
list=[1]
for fact,num in table.items():
    list_=[]
    for k in range(num+1):
        list_.extend([i*fact**k for i in list])
    list=list_
list.sort()
ans=0
for i in range(len(list)):
    if i==0:
        continue
    if list[i-1]+1==list[i]:
        continue
    m=list[i]-1
    if N//m==N%m:
        ans+=list[i]-1
print(ans)

Submission status: Runtime Error

Solution code:
import math
val = int(input())
res = 0
current = 1
while True:
    rest = val - current
    plus = math.floor(rest / current)
        
    if math.floor(val / plus) == val % plus:
        res += plus
    if current * current + current >= val:
        break
    current += 1
print(str(res))

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(){
    long long N;
    cin >> N;
    long long ans = 0;
    for(long long i=1;i*i+i<N;++i){
        if((N-i)%i==0){
            ans += (N-i)/i;
        }
    }
    cout << ans << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
N=int(input())
ans=0
M=math.ceil(N**0.5+2)
for i in range(1,M):
    if N%i==0 and N//i-i>1: ans+=N//i-1

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
	n, ans = int(input()), 0
	for i in range(1, n):
		if i*i >= n: break
		if n % i == 0:
			cand = n//i-1
			if (n%cand == n//cand): ans += cand
	if i*i == n:
		cand = n//i-1
		if (n%cand == n//cand): ans+=cand
	print(ans)


main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

anss = set()
for X in range(1, int(N**0.5)+2):
    if (N-X) % X == 0:
        m = (N-X) // X
        if N//m == N%m:
            anss.add(m)

for m in range(1, int(N**0.5)+2):
    if N//m == N%m:
        anss.add(m)

print(sum(anss))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())

m_list = []
for m in range(1,N+1):
    div = N//m
    mod = N%m
    if mod != 0:

        if div == mod:
        m_list.append(m)
print(sum(m_list))

Submission status: Runtime Error

Solution code:
N = int(input())
ans = 0
for m in range(N):
	if N//m == N%m:
		ans += 1

print(ans)

Submission status: Runtime Error

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


class Prime:
    # https://qiita.com/daikw/items/f48d6ac374255763463d
    seed_primes = [
        2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
        71, 73, 79, 83, 89, 97
    ]

    def is_prime(self, n):
        """
        prime test (hybrid)

        see also: https://qiita.com/gushwell/items/ff9ed83ba55350aaa369

        :param n:
        :return: boolean
        """
        is_prime_common = self.is_prime_common(n)
        if is_prime_common is not None:
            return is_prime_common

        if n < 2000000:
            return self.is_prime_brute_force(n)
        else:
            return self.is_prime_miller_rabin(n)

    def is_prime_common(self, n):
        if n == 1: return False
        if n in Prime.seed_primes: return True
        if any(map(lambda x: n % x == 0, self.seed_primes)): return False

    def is_prime_brute_force(self, n):
        """
        brute force prime test
        use with is_prime_common if you want to skip seed_primes

        :param n:
        :return: boolean
        """
        for k in range(2, int(math.sqrt(n)) + 1):
            if n % k == 0:
                return False
        return True

    def is_prime_miller_rabin(self, n):
        """
        miller rabin prime test
        use with is_prime_common if you want to skip seed_primes

        see also
            algorithm: https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
            implementation: https://qiita.com/srtk86/items/609737d50c9ef5f5dc59
            improvement: https://qiita.com/gushwell/items/ff9ed83ba55350aaa369

        :param n:
        :return: boolean
        """

        d = n - 1
        while d & 1 == 0:
            d >>= 1

        # use one of these lines / upper is more efficient.
        witnesses = self.get_witnesses(n)
        # witnesses = [random.randint(1, n - 1) for _ in range(100)]

        for w in witnesses:
            y = pow(w, d, n)

            while d != n - 1 and y != 1 and y != n - 1:
                y = (y * y) % n
                d <<= 1

            if y != n - 1 and d & 1 == 0:
                return False

        return True

    def get_witnesses(self, num):
        def _get_range(num):
            if num < 2047:
                return 1
            if num < 1373653:
                return 2
            if num < 25326001:
                return 3
            if num < 3215031751:
                return 4
            if num < 2152302898747:
                return 5
            if num < 3474749660383:
                return 6
            if num < 341550071728321:
                return 7
            if num < 3825123056546413051:
                return 9
            return 12

        return self.seed_primes[:_get_range(num)]

    def gcd(self, a, b):
        if a < b:
            return self.gcd(b, a)
        if b == 0:
            return a
        while b:
            a, b = b, a % b
        return a

    @staticmethod
    def f(x, n, seed):
        """
        pseudo prime generator
        :param x:
        :param n:
        :param seed:
        :return: pseudo prime
        """
        p = Prime.seed_primes[seed % len(Prime.seed_primes)]
        return (p * x + seed) % n

    def find_factor(self, n, seed=1):
        """
        find one of factor of n
        this function is based to Pollard's rho algorithm

        see also
            algorithm: https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm
            implementation: https://qiita.com/gushwell/items/561afde2e00bf3380c98

        :param n:
        :param seed:
        :return: factor
        """
        if self.is_prime(n):
            return n

        x, y, d = 2, 2, 1
        count = 0
        while d == 1:
            count += 1
            x = self.f(x, n, seed)
            y = self.f(self.f(y, n, seed), n, seed)
            d = self.gcd(abs(x - y), n)

        if d == n:
            return self.find_factor(n, seed + 1)
        return self.find_factor(d)

    def find_factors(self, n):
        primes = {}
        if self.is_prime(n):
            primes[n] = 1
            return primes

        while n > 1:
            factor = self.find_factor(n)

            primes.setdefault(factor, 0)
            primes[factor] += 1

            n //= factor

        return primes


factors_dict = Prime().find_factors(N)
factors = [1]
for p, n in factors_dict.items():
    factors_ = factors.copy()
    for i in range(1, n + 1):
        P = p**i
        for x in factors:
            factors_ += [x * P]
    factors = factors_
ans = 0
for f in factors:
    if 0 <= N // f < f - 1:
        ans += f - 1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
from operator import itemgetter
from collections import deque
from collections import defaultdict
sys.setrecursionlimit(10*5)

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

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 factorize(x):
    d=defaultdict(int)
    if x==1:
        return d[1]
    while x>1:
        for p in prime:
            if x%p==0:
                x//=p
                d[p]+=1
    return d[p]

ans=0
n=int(input())

#prime=seachPrimeNum(10**6+2)
#fctr=factorize(n)

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

Submission status: Runtime Error

Solution code:
n = int(input())

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

Submission status: Runtime Error

Solution code:
n = int(input())

ans = 0

for i in range(1, int(n ** .5) + 1):
    if n % i == 0:
        m = n // i - 1
        if n % m == n // m:
            ans += m

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

ans = 0


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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for _ in range(N)]
ans = 0
ac = 0
bc = 0
abc = 0
for st in s:
    ans += st.count('AB')
    if st[-1] == 'A' and st[0] == 'B':
        abc += 1
    else:
        if st[-1] == 'A':
            ac += 1
        elif st[0] == 'B':
            bc += 1
absoluteNum = abs(ac - bc)
basicCon = min(ac, bc)
ans += basicCon + min(abc, absoluteNum)

if (absoluteNum < abc):
    ans += abc - 1
print(ans)

Submission status: Runtime Error

Solution code:
import math

def divisor(num):
    if num < 0:
        return 0
    if num == 1:
        return [1, ]

    divisor_list = [1, ]
    divisor_list_r = [num, ]

    i = 2
    while i * i <= num:
        if num % i == 0:
            divisor_list.append(i)
        i += 1

    return divisor_list

N = int(input())
divisor_list = divisor(N)
ans = 0
for i in divisor_list:
    tmp = (N - i) // i
    if i // tmp > 0:
        continue
    ans += tmp

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())

divl = [n]
i = 2
while i * i <= n:
  if n % i == 0:
    divl.append(i)
    divl.append(n // i)
  i += 1

ans = 0
for d in divl:
  if n == d * (n // (d - 1)):
    ans += d - 1
print(ans)

Submission status: Runtime Error

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
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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

import math, itertools, operator
from math import *
from math import factorial as fact
from itertools import permutations, combinations
from functools import reduce
from statistics import mean, median, median_low, median_high, mode
# Before Python 3.5
from fractions import gcd

#import numpy
#import scipy, scipy.special
#from sympy import isprime, nextprime
#from sympy.ntheory import factorint
from sympy import divisors

inf = float('inf')

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

def perm(a, b):
    import scipy.special
    return scipy.special.perm(a, b, exact = True)

def comb(a, b):
    import scipy.special
    return scipy.special.comb(a, b, exact = True)

def dfact(n):
    import scipy.special
    return scipy.special.factorial2(n, exact = True)

def prod(l):
    return reduce(operator.mul, l)

def input_ints(inp = input, sep = ' ', conv = int):
    return map(conv, inp().split(sep = sep))

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

N = int(input())

cnt = 0
for p in divisors(N):
    m = N // p
    if not p < m:
        break
    cnt += m-1

print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
counter = 0
end_a = 0
start_b = 0
start_b_end_a = 0
for n in range(N):
    s = input()
    for i in range(len(s) - 1):
        if s[i:i + 2] == 'AB':
            counter += 1
    if s[-1] == 'A':
        end_a += 1
    if s[0] == 'B':
        start_b += 1
    if s[-1] == 'A' and s[0] == 'B':
        start_b_end_a += 1
if N == start_b_end_a:
    print(counter + min([end_a, start_b]) - 1)
else:    
    print(counter + min([end_a, start_b]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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()
    if n == 1:
        return 0
    ds = divisions(n)
    # print(ds)
    r = 0
    u = set()
    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 or True:
                r += t

    return r


print(main())

Submission status: Runtime Error

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)
        if abs(n/(n2/i) - i) < 0.8:
            ans += math.ceil(n2 / i)

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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