Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Square root of a 100 digit number in C++

'unsigned long long' can solve upto 15 digits.

Is there a way to find square-root of a 100 digit number?

like image 305
user2278992 Avatar asked Dec 26 '22 05:12

user2278992


1 Answers

You could also use Boost.Multiprecision library. 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;
}
like image 116
awesoon Avatar answered Jan 11 '23 21:01

awesoon