在python中,需要将整数均分成N等分。python divide integers N equal parts sum
代码语言:javascript复制# 拆分整数
def split_integer(m, n):
assert n > 0
quotient = int(m / n)
remainder = m % n
if remainder > 0:
return [quotient] * (n - remainder) [quotient 1] * remainder
if remainder < 0:
return [quotient - 1] * -remainder [quotient] * (n remainder)
return [quotient] * n
代码语言:javascript复制x = split_integer(98, 8)
print(x)
[12, 12, 12, 12, 12, 12, 13, 13]