美文网首页
2020-07-26 计算阶乘

2020-07-26 计算阶乘

作者: JalorOo | 来源:发表于2020-07-26 22:48 被阅读0次

https://www.luogu.com.cn/problem/P5739

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include <map>
#include <vector>
typedef long long LL;
using namespace std;

int read(){
    int x = 0,f = 1;
    char c = getchar();
    while (c<'0'||c>'9') {
        if (c=='-') {
            f = -1;
        }
        c = getchar();
    }
    while (c>='0'&&c<='9') {
        x = x*10+c-'0';
        c = getchar();
    }
    return x*f;
}

int a[13];

int ans(int n){
    if(n==1)
        return 1;
    if(a[n]!=0)
        return a[n];
    a[n] = n * ans(n-1);
    return a[n];
}

int main()
{
    cout<<ans(read())<<endl;
    return 0;
}
/*
6
91 67 80
78 89 98
78 89 91
88 99 77
67 89 64
90 66 82
============
 6 265
 4 264
 3 258
 2 244
 1 237
*/

相关文章

网友评论

      本文标题:2020-07-26 计算阶乘

      本文链接:https://www.haomeiwen.com/subject/pmfnlktx.html