You are not logged in. Please login at www.codechef.com to post your questions!

×

How can I store very very large integers accurately?

2
3

How to store large integers accurately?

asked 10 Apr '13, 14:23

rudreshwar's gravatar image

1★rudreshwar
457192531
accept rate: 50%

edited 10 Apr '13, 15:59

admin's gravatar image

0★admin ♦♦
19.7k350498541


Hello @rudreshwar,

I have written a tutorial that covers the representation of big numbers in C/C++ using arrays and then multiplication, and I applied it to the problem FCTRL...

Here is the link:

Big Numbers multiplication and representation

Maybe this can help you out! :)

Best regards,

Bruno

link

answered 11 Apr '13, 00:17

kuruma's gravatar image

3★kuruma
17.7k72143209
accept rate: 8%

If you are using c++, since it has no default support for very huge numbers, you can use one of the Big Integer classes that are already implemented or you can implement one yourself if you have time. I found a pretty good implementation called InfInt. It's fast and very easy to use. I used it in a few problems on CodeChef and it worked. Check out this link if you are interested: https://code.google.com/p/infint/

link

answered 16 Jan '14, 22:48

pale_rider's gravatar image

4★pale_rider
7215
accept rate: 0%

I have a good C++ code for BigNum:

link

link

answered 21 Sep '15, 09:03

arpa's gravatar image

6★arpa
4927
accept rate: 0%

Some problems require the use of what is called arbitrary-precision arithmetic, for example, adding together two numbers of 100 digits each.

These numbers are too large to store in an 32 or 64 bit integer. They are also too big to store in a double - a double is not accurate enough to store every single digit.

Some languages such as Java or Python have big integer classes built in. In other languages such as C/C++, the best way of handling these is to store them as strings. You can write methods to multiply, divide, add or subtract these just as you were taught in school using pen and paper.

link

answered 10 Apr '13, 14:25

admin's gravatar image

0★admin ♦♦
19.7k350498541
accept rate: 35%

If you integer is larger that maximum value of long data type e.g. 2^64 -1 then you can use BigInteger class in Java, which is just there represent to really large number. One good scenario is when you calculate the large factorials. You need BigInteger even to hold factorial of 50 accurately.

link

answered 17 Oct '15, 20:19

javinpaul's gravatar image

0★javinpaul
21
accept rate: 0%

Uses python or java its help alot in challenges and in c/c++ use array if input individually index or string .

link

answered 17 Oct '15, 22:00

darkhire21's gravatar image

2★darkhire21
5815
accept rate: 8%

is c and c++ are better for competitive purpose than java or python?

link

answered 18 May '17, 13:17

yash0307jain's gravatar image

3★yash0307jain
1
accept rate: 0%

@arpa: your bignum is either wrong or incomplete. The code for the first function: minus is in itself not complete. Perhaps you linked to the wrong file?

link

answered 05 Jan, 17:38

the_sehgal's gravatar image

1★the_sehgal
1
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,901
×1,470
×1,287
×510
×212

question asked: 10 Apr '13, 14:23

question was seen: 83,847 times

last updated: 05 Jan, 17:38