UVa 10323 【数学】

UVa 10323

题目:计算阶乘在10000~6227020800之间的值,不在范围对应输出Under或者Over。

分析:简单题、数论。因为13!=6227020800,7!<10000<8!所以计算很简单。

注意:负数情况,奇数输出Overflow,偶数输出Underflow。

其实我不明白为什么小于零时要分奇偶!而且阶乘会小于零么?

 

 1 #include<iostream>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     int n;
 7     while(cin>>n)
 8     {
 9         if((n>=0&&n<8)||(n<0&&((n*-1)%2==0))) cout<<"Underflow!"<<endl;
10         if(n==8) cout<<"40320"<<endl;
11         if(n==9) cout<<"362880"<<endl;
12         if(n==10) cout<<"3628800"<<endl;
13         if(n==11) cout<<"39916800"<<endl;
14         if(n==12) cout<<"479001600"<<endl;
15         if(n==13) cout<<"6227020800"<<endl;
16         if(n>13||(n<0&&((n*-1)%2)==1)) cout<<"Overflow!"<<endl;
17     }
18     return 0;
19 }

 

 

 

 

参考博客http://blog.csdn.net/mobius_strip/article/details/13631399

 
posted @ 2017-08-09 17:55  ╰追憶似水年華ぃ╮  阅读(272)  评论(0编辑  收藏  举报