稍大数的阶乘判题时的一个邪门问题
本文最后更新于 415 天前,其中的信息可能已经有所发展或是发生改变。

先看代码

    #include<iostream>
    #include<iomanip>
    using namespace std;
    double	 Fact(int  n) {
    	int  i;
    	double  result = 1;
    	for (i=2; i<=n; i++)
    		result *= i;
    	return result;
    }
    int main() {
    	int n;
    	cin>>n;
    	for(int nc=2; nc<=n; nc++) {
    		if(nc%2==0) {
    			cout<<nc<<"! = "<<fixed<<setprecision(0)<<Fact(nc)<<endl;
    			//cout<<nc<<"! = "<<(long long int)Fact(nc)<<endl;
    		}
    	}
    }

注意这俩句

    cout<<nc<<"! = "<<fixed<<setprecision(0)<<Fact(nc)<<endl;
    cout<<nc<<"! = "<<(long long int)Fact(nc)<<endl;

上面的语句判题就是对的,下面的判题就是错的

n=50时:

上面语句是这个输出

50
2! = 2
4! = 24
6! = 720
8! = 40320
10! = 3628800
12! = 479001600
14! = 87178291200
16! = 20922789888000
18! = 6402373705728000
20! = 2432902008176640000
22! = 1124000727777607680000
24! = 620448401733239409999872
26! = 403291461126605650322784256
28! = 304888344611713836734530715648
30! = 265252859812191032188804700045312
32! = 263130836933693517766352317727113216
34! = 295232799039604119555149671006000381952
36! = 371993326789901177492420297158468206329856
38! = 523022617466601037913697377988137380787257344
40! = 815915283247897683795548521301193790359984930816
42! = 1405006117752879788779635797590784832178972610527232
44! = 2658271574788448529134213028096241889243150262529425408
46! = 5502622159812088456668950435842974564586819473162983440384
48! = 12413915592536072528327568319343857274511609591659416151654400
50! = 30414093201713375576366966406747986832057064836514787179557289984

下面的输出就是这样子了

50
2! = 2
4! = 24
6! = 720
8! = 40320
10! = 3628800
12! = 479001600
14! = 87178291200
16! = 20922789888000
18! = 6402373705728000
20! = 2432902008176640000
22! = -9223372036854775808
24! = -9223372036854775808
26! = -9223372036854775808
28! = -9223372036854775808
30! = -9223372036854775808
32! = -9223372036854775808
34! = -9223372036854775808
36! = -9223372036854775808
38! = -9223372036854775808
40! = -9223372036854775808
42! = -9223372036854775808
44! = -9223372036854775808
46! = -9223372036854775808
48! = -9223372036854775808
50! = -9223372036854775808

long long double也沦陷了(悲

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇