how to handle integers having say 25 digits in c++ solve the proble开发者_运维百科ms..
Typically using a big-number library such as GNU MP or bigint.
In elementary school you probably learned how to do basic 4 operations (+-*/) manually on paper. Kids treat numbers as sequence of digits and process digit-by-digit.
(at least kids in Poland, where I grew up, used to learn it when I was young)
This method works for any big numbers. Adding 25-digit-long numbers works the same as adding 3-digit-long, only slower.
You have to recall how was it done when you were a kid and write a computer program that processes numbers in this way.
For extra performance and programmer credibility write it using base 65536 rather than base 10.
"The Art of Computer Programming" by Donald Knuth, volume two "Seminumerical algorithms" has some useful info, if you're planning to implement it yourself rather than use a library function.
Google revealed:
Arjen Lenstra's LIP package
Victor Shoup's NTL packaage
Try using MAMP
http://www.tc.umn.edu/~ringx004/mapm-main.html
I did a similar thing at Uni in Pascal to add and subtract extrememly large numbers. Simply you need to handle any number above the limit of your numbers, then any overflow goes into a larger bucket. The reverse applies (though you need to be more careful) for subtraction.
If you want to handle multiplication and division, and you don't want to use a third party package, then I refer you to a copy of Mike Abrash's Zen of Graphics Programming. In it he lists 32bit Multiplication and Divisions using 16bit numbers. It's in assembler, but you can handle that can't you?-)
精彩评论