使用 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
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP