4

'unsigned long long' can solve upto 15 digits.

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

Jens Gustedt
  • 74,635
  • 5
  • 99
  • 170
user2278992
  • 93
  • 1
  • 2
  • 1
    I know this is probably not what you're looking for, but in case you don't need an exact result, you can just use `double`. – Detheroc Apr 14 '13 at 11:19
  • 2
    @Detheroc that would be a good first step to compute the real value with an algorithm like the newton method. – didierc Apr 14 '13 at 11:51

3 Answers3

4

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;
}
awesoon
  • 30,028
  • 9
  • 67
  • 92
3

Definitely. One easy way would be to use the GNU multi-precision library's mpz_sqrt() function.

John Zwinck
  • 223,042
  • 33
  • 293
  • 407
3

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

Depending on if its homework or not you might be able to use a premade lib to handle bignums

krs
  • 3,808
  • 18
  • 21