Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #50803 > unrolled thread

Re: Storing a very large number

Started byGary Herron <gherron@digipen.edu>
First post2013-07-17 13:02 -0700
Last post2013-07-17 13:02 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Storing a very large number Gary Herron <gherron@digipen.edu> - 2013-07-17 13:02 -0700

#50803 — Re: Storing a very large number

FromGary Herron <gherron@digipen.edu>
Date2013-07-17 13:02 -0700
SubjectRe: Storing a very large number
Message-ID<mailman.4812.1374091807.3114.python-list@python.org>
On 07/17/2013 12:21 PM, Hasit Mistry wrote:
> I came across a problem that requires me to store a very large number 
> (say >10^100). How do I do it efficiently?
> And also, how do I select a particular number (say 209th) from that 
> very large number?
> I am relatively new to Python.
>
> Thank you in advance.
>

Python already has long numbers (integers) built in.:

 >>> 10**100
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000L

The 'L' on the end notifies you it's a *long* int.  I can't speak about 
its efficiency, but I assume it's OK.

By 209th number, do you mean 209th *digit*?    I'd say just get a string 
representation and index the 209th character:

 >>> str(12**345)
'2077446682327378559843444695582704973572786912705232236931705903179519704325276892191015329301807037794598378537132233994613616420526484930777273718077112370160566492728059713895917217042738578562985773221381211423961068296308572143393854703167926779929682604844469621152130457090778409728703018428147734622401526422774317612081074841839507864189781700150115308454681772032'
 >>> str(12**345)[209]
'1'

Gary Herron


-- 
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web