from typing import Union
def isdivisor(num):
lresult = []
for i in range(1, num // 2 + 1):
if num % i == 0:
lresult.append(i)
return lresult
def buddy(start: int, limit: int) -> Union[list, str]:
for i in range(start, limit):
lresult1 = isdivisor(i)
lsum = sum(lresult1) - 1
lresult2 = isdivisor(lsum)
if sum(lresult2) - 1 == i and i < lsum:
return [i, lsum]
return "Nothing"
def buddy(start: int, limit: int) -> Union[list, str]:
import math
def inner(n):
# 求因子
res = 1
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
if i != n // i:
res += i + n // i
else:
res += i
return res
n = start
while n<=limit:
res= inner(n)
if res-1<=n or inner(res-1)-1!=n:
n+=1
else:
return [n,res-1]
else:
return "Nothing"
from typing import Union
def buddy(start: int, limit: int) -> Union[list, str]:
i_list = []
j_list = []
for n in range(start, limit + 1):
for i in range(1, n):
if n % i == 0:
i_list.append(i)
sn = sum(i_list)
i_list = []
m = sn - 1
if m <= n:
continue
for j in range(1, m):
if m % j == 0:
j_list.append(j)
sm = sum(j_list)
j_list = []
if sm == n + 1:
return [n, m]
else:
continue
return "Nothing"
assert buddy(10, 50) == [48, 75]
assert buddy(2177, 4357) == "Nothing"
assert buddy(57345, 90061) == [62744, 75495]
assert buddy(1071625, 1103735) == [1081184, 1331967]
def buddy(start: int, limit: int) -> Union[list, str]:
def find_true_divisor(num): # 返回真除数集合
return [i for i in range(1, num) if num % i == 0]
for n in range(start, limit + 1):
m = sum(find_true_divisor(n)) - 1
if m > n and sum(find_true_divisor(m)) - 1 == n: # m 必须大于 n
return [n, m]
else:
return "Nothing"