[英]Square root of a 100 digit number in C++
'unsigned long long' can solve upto 15 digits. 'unsigned long long'最多可以解决15位数。
Is there a way to find square-root of a 100 digit number ? 有没有办法找到100位数字的平方根?
You could also use Boost.Multiprecision library. 您还可以使用Boost.Multiprecision库。 This library provides wrappers for some popular multiprecision implementations.
该库为一些流行的多精度实现提供了包装器。
#include <iostream>
#include <string>
#include <utility>
#include <boost/multiprecision/mpfr.hpp>
int main()
{
std::string s(100, '0');
s.at(0) = '1';
boost::multiprecision::mpfr_float_100 f(std::move(s));
boost::multiprecision::mpfr_float_100 sqrt = boost::multiprecision::sqrt(f);
std::cout << sqrt.str() << std::endl;
return 0;
}
Definitely. 当然。 One easy way would be to use the GNU multi-precision library's mpz_sqrt() function.
一种简单的方法是使用GNU多精度库的mpz_sqrt()函数。
This question isnt really related to C++, but here is a list of methods you can use http://en.wikipedia.org/wiki/Methods_of_computing_square_roots 这个问题与C ++没有关系,但是这里有一个你可以使用的方法列表http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
Depending on if its homework or not you might be able to use a premade lib to handle bignums 根据是否作业,您可以使用预制的lib来处理bignums
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.