列表

详情


NC14323. Factorial

描述

Hill was a clever boy,he like math very much.Today teacher give him a question.
calculate N! . But Hill was tired,he need to sleep,so let you help him to calculate N!.

what is N!
N! = 1*2*3*......*N

Hey, you need to think about 0! . Do you?

输入描述

There are multiple test cases. The first line is an positive integer T indicating the number of test cases.(0<T<=1000)
For each test case:
A positive integer N(0<=N<=20)

输出描述

For each test case, output one line.

示例1

输入:

3
1
2
3

输出:

1
2
6

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

pypy3(pypy3.6.1) 解法, 执行用时: 37ms, 内存消耗: 18596K, 提交时间: 2021-04-22 17:04:31

def solve():
    n=int(input())
    re=1
    for i in range(1,n+1):
        re*=i
    print(re)
for _ in range(int(input())):
    solve()

Python3 解法, 执行用时: 26ms, 内存消耗: 4472K, 提交时间: 2021-12-14 00:50:03

import math
[print(math.factorial(int(input()))) for i in range(int(input()))]

上一题