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

×

Storing very large number

How can we store a very large number in c or c++ ? For example to calculate 99! (contains about 150 digits), how to do this in efficient manner ?

asked 09 Jan, 23:25

hmtupd123's gravatar image

2★hmtupd123
373
accept rate: 0%

edited 09 Jan, 23:30

you should use an array or string .you can handle even bigger than you are talking.

(12 Jan, 19:43) mahipalsaran3★

@hmtupd123 You can use BIG INTEGERS in C++ using boost library.

Here is an implementation of BIG INTEGERS in C++ using boost library (link).

link

answered 09 Jan, 23:40

srd091's gravatar image

5★srd091
1.5k111
accept rate: 42%

Hi. The best answer to your question would be the blog post on codechef: https://discuss.codechef.com/questions/7349/computing-factorials-of-a-huge-number-in-cc-a-tutorial

link

answered 12 Jan, 14:58

drp48603's gravatar image

0★drp48603
252
accept rate: 0%

For storing such large numbers you have to make use of the arrays or vectors which are containers that can store such large values .... and the number may pe interpreted as the digits seperated in different cells of the array.

link

answered 09 Jan, 23:42

sagarpant74's gravatar image

3★sagarpant74
1
accept rate: 0%

You can't store such a big number in any of the data types available in C or C++ but even if you want to store the value of say 99! or even 100! then have a look at this blog post of CodeChef.

link

answered 10 Jan, 08:30

coderman15's gravatar image

2★coderman15
31
accept rate: 0%

You have to use array to store such a large number.you can see the codechef tutorial for small factorial (FCTRL2).it is already discussed there.So I don't think i should repeat it here .you can easily check that tutorial.Or you can easily google small factorial codechef...you will get appropriate results.Here is the link
https://www.codechef.com/wiki/tutorial-small-factorials Happy Coding:).

link

answered 10 Jan, 08:33

panjiara2114's gravatar image

2★panjiara2114
11
accept rate: 0%

edited 10 Jan, 08:35

I would suggest you to move to Java for this specific problem due to the availability of BigInteger. However , in C/C++, I would suggest you to read the implementation of BigInteger, and write something similar in C++, supporting only the operations that are common.

link

answered 10 Jan, 22:03

rajarshi_basu's gravatar image

5★rajarshi_basu
4566
accept rate: 11%

maybe u should use string or array in this case u can handle even larger than what you are talking here.

link

answered 12 Jan, 19:42

mahipalsaran's gravatar image

3★mahipalsaran
2386
accept rate: 8%

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:

×163
×41

question asked: 09 Jan, 23:25

question was seen: 987 times

last updated: 12 Jan, 19:43