📜  使用Boost精度库进行大量因子分解

📅  最后修改于: 2021-05-30 09:26:33             🧑  作者: Mango

现在,我们已经给出了很多数字,我们可以使用boost multiprevision库轻松找到这个数字的阶乘。
Boost库在当前的1.53.0版本中包括了一个新的多精度库,供需要比64位精度更高的C++程序员使用。

例子:

Input : 100
Output :  933262154439441526816992388562667004-
         907159682643816214685929638952175999-
         932299156089414639761565182862536979-
         208272237582511852109168640000000000-
         00000000000000



Input :50
Output : 3041409320171337804361260816606476884-
         4377641568960512000000000000
// CPP program to find factorial of large 
// number using boost library.
#include 
#include 
using boost::multiprecision::cpp_int;
using namespace std;
  
cpp_int Factorial(int number)
{
    cpp_int num = 1;
    for (int i = 1; i <= number; i++)
        num = num * i;
    return num;
}
  
int main()
{
    int number = 100;
    cpp_int fact = Factorial(number);
    cout << fact << endl;
    return 0;
}

输出:-

933262154439441526816992388562667004-
         907159682643816214685929638952175999-
         932299156089414639761565182862536979-
         208272237582511852109168640000000000-
         00000000000000
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”