階乘之和(高精度)

2021-10-23 15:43:13 字數 1566 閱讀 6866

題目描述

用高精度計算出s=1!+2!+3!+…+n!(n≤50)

其中「!」表示階乘,例如:5!=5×4×3×2×1。

輸入格式

乙個正整數n。

輸出格式

乙個正整數s,表示計算結果。

輸入輸出樣例

輸入

3
輸出
9
//過載運算子

#include

#include

#include

#include

using

namespace std;

struct fantastic //過載

fantastic operator=(

const

char

*num)

return

*this;}

fantastic operator=(

const

int num)

fantastic (

const

int num)

fantastic (

const

char

* num)

fantastic operator+(

const fantastic &a)

//過載 「+」

if(c.s[c.len-1]

==0)return c;

} fantastic operator*(

const fantastic &x)

//過載 「*」

if(c.s[c.len-1]

==0)return c;}}

;ostream&

operator

<<

(ostream &out,

const fantastic& x)

//過載輸出

return out;

}istream&

operator

>>

(istream &in,fantastic &x)

//過載輸入

intmain()

cout<}

//套用高精度加法,乘法

#include

using

namespace std;

intmain()

,b[1005]=

,n,j;

cin>>n;

a[0]

=b[0]=

1;for(i=

2;i<=n;i++

)for

(j=0

;j<

100;j++)}

for(j=

0;j<

100;j++)}

}for

(i=100

;i>=

0&&a[i]==0

;i--);

for(j=i;j>=

0;j--

)return0;

}

高精度計算 階乘之和

include include include define maxn 2000 define maxm 2001 using namespace std int fact 51 maxm int temp maxm 階乘之和 本題需要注意的地方 1。bigint int 小的int不必轉換為big...

求階乘之和 高精度

一道來自洛谷的求階乘之和的題 由於題目中給出的資料範圍較大,即使用long long也會造成資料溢位,所以要用到高精度的運算.學習了高精度運算之後就知道,可以用陣列來儲存範圍大的整數,於是,這道題我就是將資料從1開始依次相乘,每乘一次就將結果儲存盡數組當中,然後與前一次乘積結果相加以達到高精度求和的...

P1009 階乘之和 高精度

題目描述 用高精度計算出s 1 2 3 n n 50 s 1 2 3 n n 50 s 1 2 3 n n 50 其中 表示階乘,例如 5 5 4 3 2 15 5 times 4 times 3 times 2 times 15 5 4 3 2 1。輸入格式 乙個正整數nnn。輸出格式 乙個正整數...