#P1010. for 循环结构 - 1 到 n 的累乘(阶乘)

for 循环结构 - 1 到 n 的累乘(阶乘)

学习目标:9090 秒内 一气呵成 打完代码,并且运行正确,并且提交正确。

题目描述

输入一个整数 nn,计算 s=n!s= n!n!n! 表示 nn 的阶乘。n!=1×2×3×4××nn!=1\times2\times3\times4\times…\times n ,其中 nn 由键盘输入。输出 ss 的值。

输入格式

一行一个整数 nn

输出格式

一行一个整数 nn 的阶乘。

4
24

数据规模与约定

n20n\leq 20

提示

1、int的范围是 21-21 亿 到 $+21亿,

可以发现,当 n=13n=13 开始,ss 就无法用 int\texttt{int} 表示了。

所以要使用 long long\texttt{long long}

请看以下代码就全明白了。

#include<cstdio>
using namespace std;
 
int main()
{
    long long a,b,s;
    scanf("%lld %lld",&a,&b);
    s=a+b;
    printf("%lld\n",s);
    return 0;
}