大数乘法计算器——在阶乘中的应用

def mul_list(la: list, lb: list) -> list:
    c = 0
    product = [0] * (len(la) + len(lb))
    for a in range(len(la)):
        for b in range(len(lb)):
            temp = product[a + b] + la[a] * lb[b]
            product[a + b] = temp % 10
            if temp > 9:
                product[a + b + 1] += temp // 10
    return product


def func():
    n = int(input().strip())
    
    product = [1]
    for i in range(2, n + 1):
        li = []
        while i:
            li.append(i % 10)
            i //= 10
        product = mul_list(product, li)
        if product[-1] == 0:
            product.pop(-1)
    
    if product[-1] == 0:
        product.pop(-1)
    product.reverse()
    product = list(map(str, product))
    print("".join(product))


if __name__ == "__main__":
    func()

  

posted @ 2020-08-04 15:08  玉北  阅读(209)  评论(0编辑  收藏  举报