大整数数据类型:
我们可以根据需要使用 int128_t、int256_t、int512_t 或 int1024_t 数据类型。通过使用这些数据类型,我们可以轻松实现高达 1024 位的精度。
以下是用于计算大数乘积的 C++ 实现代码:
// CPP Program to demonstrate Big Integer data type
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
int128_t boost_product(long long A, long long B)
{
int128_t ans = (int128_t)A * B;
return ans;
}
int main()
{
long long first = 98745636214564698;
long long second = 7459874565236544789;
cout << "Product of " << first << " * " << second
<< " = \n"
<< boost_product(first, second);
return 0;
}
输出:
Product of 98745636214564698 * 7459874565236544789 =
736630060025131838840151335215258722