zoukankan      html  css  js  c++  java
  • 14323 Factorial

    链接:https://ac.nowcoder.com/acm/problem/14323
    来源:牛客网

    题目描述

    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
    题意:
    求T组N的阶乘

    #include<iostream>
    #include<algorithm>
    #include<cstdlib>
    #include<cstdio>
    #include<queue>
    #include<stack>
    #include<cstring>
    #include<string.h>
    #include<cmath>
    using namespace std;
    const int maxn=10020;
    long long sum[maxn];
    long long dfs(int n){
        int i;
        if(n==0){
            return 1;
        }
        else if(n==1){
            
            return 1;
        }
        else if(sum[n]!=0){
            return sum[n];
        }
        else{
            for(int i=2;i<=n;i++)
            sum[i]=sum[i-1]*i;
            return sum[n];
        }
    }
    
    int main(){
        int T,N;
        sum[1]=1;
        long long m;
        scanf("%d",&T);
        while(T--){
            scanf("%d",&N);
            m=dfs(N);
            printf("%lld
    ",m);
        } 
        
        return 0;
    }
  • 相关阅读:
    day23 GUI
    day17JDK5.0新特性与正则表达式
    day12-day15集合
    day11线程
    day10-JavaAPI
    day09面向对象-
    day08面向对象-内部类、异常
    day06面向对象
    Idea导入Eclipse中的Maven Web(SSM)
    java给图片添加水印
  • 原文地址:https://www.cnblogs.com/dreamzj/p/13894003.html
Copyright © 2011-2022 走看看