使用 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.