-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!

6
  • 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. ;) Commented Sep 1, 2015 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. Commented Sep 1, 2015 at 17:24
  • Is competitive programming really waste to time ?Please share your perspective. Commented Sep 1, 2015 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 quora.com/Competitive-Programming. Commented Sep 1, 2015 at 17:30
  • 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. Commented Sep 1, 2015 at 18:02

1 Answer 1

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.