Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

Factorial ของตัวเลขขนาดใหญ่ด้วย Boost Multiprecision Library


เพื่อหา Factorial ของตัวเลขขนาดใหญ่ เราสามารถใช้ Boost Library ไลบรารีนี้ให้ Precision สูง ด้วย Boost Multiprecision Library เราสามารถได้ Precision มากกว่า 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