Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50803
| Date | 2013-07-17 13:02 -0700 |
|---|---|
| From | Gary Herron <gherron@digipen.edu> |
| Subject | Re: Storing a very large number |
| References | <51E6EEC3.50404@lavabit.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4812.1374091807.3114.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Storing a very large number Gary Herron <gherron@digipen.edu> - 2013-07-17 13:02 -0700
csiph-web