-3

I would like to know how to use very large numbers (being accurate 10^100 in C++) for competitive programming. I know libraries like GMP exist but they can't be used sites like SPOJ or CodeChef.

I have used strings, however it takes lot of time to implement it. Now I would like to know what efficient methods do other programmers use and resources to learn those methods. Thanks!

mtszkw
  • 2,717
  • 2
  • 17
  • 31
Golden_flash
  • 492
  • 1
  • 6
  • 14
  • 5
    Implement your own `BigDecimal` or `BigInteger` class, using a dynamically-sized array of smaller integers, and using arbitrary precision arithmetic for actual operations. Alternatively, stop wasting your time on competitive programming. ;) – Daniel Kamil Kozar Sep 01 '15 at 17:16
  • @DanielKamilKozar _"stop wasting your time on competitive programming"_ to extend on that: ... and specifically asking questions for insight on the inner workings of their engines on StackOverflow. – πάντα ῥεῖ Sep 01 '15 at 17:24
  • Is competitive programming really waste to time ?Please share your perspective. – Golden_flash Sep 01 '15 at 17:26
  • @Golden_flash There's a prejudice against it at SO, for some reason, so it's best not to mention it in your question (i.e., write your question as a programming question, not a CP question). To ask CP-specific questions, try https://www.quora.com/Competitive-Programming. – RedGreenCode Sep 01 '15 at 17:30
  • Why not just look at the libraries that are the most like what you want? If GMP is what you want, then look at how GMP works. The source code is available. – David Schwartz Sep 01 '15 at 17:35
  • 2
    @Golden_flash: I think the issue with competitive programming is the horrific coding styles used. Most of the code is barely readable, loaded with idiotic macros and single-character variable names. Write-only code that wouldn't pass the simplest code review in the real world. – Blastfurnace Sep 01 '15 at 18:02

1 Answers1

0

I would like to know what efficient methods other programmers use

Most of the time you can't use any third-party libraries when submitting your solutions to online judge systems like SPOJ or at contests (however some contests need only .out files, so it doesn't matter how you get them).

Since you cannot use anything external, competitive programmers write their BigNum classes on their own. It is not really so hard using dynamic arrays or data structures like std::string in C++.


How to?

Practice is your best friend when you are trying to beat and solve online judge/contest problems.
Paper, pencil, your mind, nothing else is required to find out how to implement your BigNum class.

Consider how you can read/write big numbers as std::string, then go one level further and try to add/remove leading-zeros, count a sum of two big numbers... and then, further things will be easier.

mtszkw
  • 2,717
  • 2
  • 17
  • 31