简单 时间限制:1000MS 内存限制:64MB分数:100 OI排行榜得分:12(0.1*分数+2*难度)
递归 第十五讲(Level2)
描述
什么是阶乘呢?比如5的阶乘可以写作5!(读作:5的阶乘)。它表示的意思就是1×2×3×4×5,所以5!等于120。现在用递归求n!,将结果输出。
输入描述
一个整数n。(1≤n≤10)
输出描述
一个整数,n!的结果。
样例输入 1
6
样例输出 1
720
(嘿嘿嘿,又是前奏巨长的代码)
#include<bits/stdc++.h>
//#define ONLINE_TEST
#ifdef ONLINE_TEST
#define getchar() p1 == p2 && (p2 = (p1 = buf) + fread (buf, 1, 1 << 18, stdin), p1 == p2) ? EOF : *p1++
#define flush() fwrite (buffer, 1, p11 + 1, stdout), p11 = -1
#define putchar(c) p11 == p22 ? flush(), buffer[++p11] = c : buffer[++p11] = c
char buf[1 << 18], *p1 = buf, *p2 = buf;
char buffer[1 << 18];
int p11 = -1;
const int p22 = (1 << 18) - 1;
#endif
template <typename T> inline void rei (T &x) {
x = 0; bool f = 1; int ch;
while (!isdigit (ch = getchar ())) f = ch != '-';
if (f) do x = x * 10 + (ch & 15); while (isdigit (ch = getchar ()));
else do x = x * 10 - (ch & 15); while (isdigit (ch = getchar ()));
}
template <typename T> inline void wri (T x) {
if (x < 0) putchar ('-'), x = ~x + 1;
static int stk[40], top = 0;
while (x) stk[++top] = x % 10, x /= 10;
if (top == 0) stk[++top] = 0;
while (top) putchar (stk[top--] ^ 48);
putchar (' ');
}
template <typename T, typename... Args> inline void rei (T &x, Args&... args) {rei (x), rei (args...);}
template <typename T, typename... Args> inline void wri (T x, Args... args) {wri (x), wri (args...);}
template <typename T1, typename T2> inline T1 &cmin (T1 &a, const T2 &b) {return a > b ? a = b : a;}
template <typename T1, typename T2> inline T1 &cmax (T1 &a, const T2 &b) {return a < b ? a = b : a;}
typedef long long LL;
typedef unsigned long long ULL;
#define fir(i,a,b,...) for (register int i = (a), ##__VA_ARGS__; i <= (b); i++)
#define firr(i,a,b,...) for (register int i = (a), ##__VA_ARGS__; i >= (b); i--)
#define cls(a) memset (a, 0, sizeof a)
#define mset(a,b) memset (a, b, sizeof a)
#define dbug(x) (void)(cerr << #x " = " << x << endl)
using namespace std;
LL jc(int n){
if(n==0) return 1;
return jc(n-1)*n;
}
signed main () {
int n;
cin>>n;
cout<<jc(n);
#ifdef ONLINE_TEST
flush ();
#endif
return 0;
}
欢迎加入AKIOI团队
(虽然我也只是个成员)