先看代码
#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时:
上面语句是这个输出
502! = 24! = 246! = 7208! = 4032010! = 362880012! = 47900160014! = 8717829120016! = 2092278988800018! = 640237370572800020! = 243290200817664000022! = 112400072777760768000024! = 62044840173323940999987226! = 40329146112660565032278425628! = 30488834461171383673453071564830! = 26525285981219103218880470004531232! = 26313083693369351776635231772711321634! = 29523279903960411955514967100600038195236! = 37199332678990117749242029715846820632985638! = 52302261746660103791369737798813738078725734440! = 81591528324789768379554852130119379035998493081642! = 140500611775287978877963579759078483217897261052723244! = 265827157478844852913421302809624188924315026252942540846! = 550262215981208845666895043584297456458681947316298344038448! = 1241391559253607252832756831934385727451160959165941615165440050! = 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也沦陷了(悲