D
D
Dmitry Khaperets2015-04-23 14:42:30
Mathematics
Dmitry Khaperets, 2015-04-23 14:42:30

How to perform mathematical operations with large numbers?

Created an algorithm for determining the number of prime.
I wrote a program in C++, which checks the largest prime number 18446744073709551557 from the range 1 ... 2^64 - 1 in 7-8 seconds.
Now I would like to work with numbers of arbitrary length, but I do not know how.
In general, you need to perform three operations with large numbers: calculating the square root of a number (sqrt), rounding the number to the nearest integer (ceil) and modulo (remainder of division, %).
Tell me how you can organize these three operations on superlarge numbers in C++.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Kudryavtsev, 2015-04-23
@kumaxim

Phrase for Google "Long arithmetic C++"

V
Vladimir Martyanov, 2015-04-23
@vilgeforce

There is a ready and fast enough implementation in openSSL - BN. You can use it, you can look at their sorts (but the devil will break his leg there). There is also MIRACL (also with sorts), but they have performance problems and the documentation is not very good in places. You can look at GMP, but have not personally used it.

V
Vitaly Vitrenko, 2015-04-23
@Vestail

GMP

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question