阶乘定义拓展
Factorial! You Must be Kidding!!!
题目大意
注意事项
审题, n < 0 n < 0 n<0 也要利用公式算, n n n 是奇数时结果为 ∞ \infty ∞,偶数时结果 − ∞ -\infin −∞
参考代码
//poj GCC
#include<iostream>
#include<vector>
#include<cstring>
#include<cstdio>
#include<climits>
#include<cmath>
#include<algorithm>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<stack>
//#define LOCAL //提交的时候一定注释
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
typedef long long LL;
using namespace std;
const int maxn = 1e5 + 10;
const int MOD = 1e9 + 7;
const int N = 13;
const LL fact1 = 10000, fact2 = 6227020800;
int readint() {
int x; scanf("%d", &x); return x;
}
LL fac[N + 1];
void getF() {
fac[0] = 1;
for(int i = 1; i <= N; i++) {
fac[i] = 1LL * i * fac[i - 1];
}
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
getF();
int n;
while (~scanf("%d", &n)) {
if (n > 13 || (n < 0 && (-n) % 2)) printf("Overflow!\n");
else if ((n >= 0 && fac[n] < fact1) || (n < 0 && (-n) % 2 == 0)) printf("Underflow!\n");
else printf("%lld\n", fac[n]);
}
return 0;
}