大數乘法計算器——在階乘中的應用
阿新 • • 發佈:2020-08-04
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(): # please define the python3 input here. # For example: a,b = map(int, input().strip().split()) n = int(input().strip()) # please finish the function body here. 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) # please define the python3 output here. For example: print(). if product[-1] == 0: product.pop(-1) product.reverse() product = list(map(str, product)) print("".join(product)) if __name__ == "__main__": func()