Search code examples
c++stringbignum

Division of a big number of 100 digits stored as string


I have a 100 digit number stored as string. I want to divide this number with an integer less than 10. How do I efficiently divide a big integer stored as a string with an integer?


Solution

  • You can check the big integer library.

    You can use this library in a C++ program to do arithmetic on integers of size limited only by your computer's memory. The library provides BigUnsigned and BigInteger classes that represent nonnegative integers and signed integers, respectively. Most of the C++ arithmetic operators are overloaded for these classes, so big-integer calculations are as easy as:

    #include "BigIntegerLibrary.hh"
    
    BigInteger a = 65536;
    cout << (a * a * a * a * a * a * a * a);
    
    (prints 340282366920938463463374607431768211456)
    

    Also check GMP