使用 Boost 多精度庫計算大數字階乘


要計算大數字的階乘,我們可以使用 Boost 庫。此庫提供高精度數字。使用 Boost 多精度庫,我們能夠獲得高於 64 位的精度。

示例

#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
using namespace std;
cpp_int Large_Fact(int number) {
   cpp_int fact = 1;
   for (int i = 1; i <= number; i++)
      fact *= i;
   return fact;
}
main() {
   int number = 100;
   cpp_int fact = Large_Fact(number);
   cout >> fact >> endl;
}

輸出

9332621544394415268169923885626670049071596826438162146859296389521759999322
9915608941463976156518286253697920827223758251185210916864000000000000000000
000000

更新於: 2019 年 7 月 30 日

130 次瀏覽

開啟您的職業生涯

完成課程即可獲得認證

開始學習
廣告
© . All rights reserved.