red_coder's blog

By red_coder, 12 years ago, In English

Hey guys i was wondering just like BigInteger in Java is there any way to handle very large numbers along with all the arithmetic operations in c++....

  • Vote: I like it
  • -20
  • Vote: I do not like it

| Write comment?
»
12 years ago, # |
Rev. 2   Vote: I like it +11 Vote: I do not like it

No , you have to handle it in array

you can code a class or data struct to handle big numbers

  • »
    »
    12 years ago, # ^ |
      Vote: I like it -27 Vote: I do not like it

    no there must be some way i am sure. Handling with array may create some problems and also too much code to write manually for implementation.

    • »
      »
      »
      12 years ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      If the competition allows pre-written code, then there is no problem. Otherwise, addition, subtraction, multiplication and division by a small number are easily implementable within minutes (try to write them one or two times and you'll get the feel of it).

      The is no support for big numbers in the standard library, so the above is the only thing you can do.

      • »
        »
        »
        »
        12 years ago, # ^ |
          Vote: I like it -25 Vote: I do not like it

        andreyv dear i wanted to do some modular operations with large numbers not some basic addition or substraction.

        • »
          »
          »
          »
          »
          12 years ago, # ^ |
            Vote: I like it +1 Vote: I do not like it

          when you do division you do modular at the same time because the answer of the modular is the final reminder of the division!

          I don't know if there is a way better than this (that has better complexity)

    • »
      »
      »
      12 years ago, # ^ |
        Vote: I like it +10 Vote: I do not like it

      Yes, there is well-known way — as I know most of C++ contestants with high rating have sufficient skills in java and use this language for these rare problems.

»
12 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can use Gmp in use normal,but in competition search or create your own implementation.

  • »
    »
    12 years ago, # ^ |
      Vote: I like it -13 Vote: I do not like it

    dude i dont have any idea how to use GMP. After download what to do???

    • »
      »
      »
      12 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Compile it and then link your programs against gmp library.

»
12 years ago, # |
  Vote: I like it +6 Vote: I do not like it

the best solution i see is to learn some basic java....

  • »
    »
    12 years ago, # ^ |
    Rev. 2   Vote: I like it -20 Vote: I do not like it

    don't forget that C++ is twice faster than java

    • »
      »
      »
      12 years ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      But Java's BigInteger will be faster than your own implementation which you can write on a real contest. It can be not true for multiplication if you'll use FFT.

    • »
      »
      »
      12 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      There are quite a few problems in contests and online judges for which it is important. One per thousand I think, or less.

      Look at this guy who uses Java quite often. ;-)