本文介绍了大数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在考虑编写一个程序来生成世界上最大的素数,这只是为了它的乐趣。这将需要

能够将8000000位数字保存到内存中(25兆位,或者只需一个变量就可以获得超过3兆内存的
...)I也会
需要几个较小的变量。这是因为我越来越优化了一个主要的
数字生成器,直到我想到尝试使用python尝试找到有史以来最大的
。有任何想法吗?我可能会尝试最终在大型机上运行这个
,虽然他们可能不喜欢它很多...我会在家里运行它计算机首先测试它。无论如何,

让我知道是否有办法让python支持数字如此之高。

谢谢!

解决方案





Python已经支持大数字:




然而,你可能想要看看像gmpy这样的东西,因为你会得到更好的性能。


< mike

-

Mike Meyer< mw*@mired.org>

独立的WWW / Perforce / FreeBSD / Unix顾问,电子邮件以获取更多信息。




给定名为Decimal的模块在Python 2.4中,我建议你重命名

你的图书馆。

-

Giovanni Bajo

I''ve been thinking about writing a program to generate the world''s
largest prime numbers, just for the fun of it. This would require being
able to hold an 8000000 digit number into memory (25 megabits, or a
little over 3 megs of memory for just one variable...) I would also
need several smaller variables. This came about as I optimised a prime
number generator more and more, until I came with the idea to try to
find the largest ever, using python. Any ideas? I''ll probably try to
run this on a mainframe eventually, although they might not like it
very much... I''ll run it on my home computer to first test it. Anyways,
let me know if there''s a way to make python support numbers so high.
Thanks!

解决方案




Python already supports numbers that large:



However, you probably want to look into something like gmpy, as you''ll
get better performance out of it.

<mike
--
Mike Meyer <mw*@mired.org>http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



Given the module named "Decimal" in Python 2.4, I''d suggest you to rename
your library.
--
Giovanni Bajo


这篇关于大数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 20:05