素数 [英] prime number

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

问题描述

我在编写一个计算出素数的程序时遇到了麻烦。

有没有人知道如何编写它?我所知道的只是n> 2
如果没有2和n之间的数字n(包含),则
是正常的。

除以n。

解决方案

2005年5月29日19:55:32 -0700,lostinpython

< sh *************** @ hotmail.com>写道:

我在编写一个计算出素数的程序时遇到了麻烦。
有没有人知道如何编写它?我所知道的只是n> 2如果n和(n)之间没有数字n(包含)之间没有数字,则n = n。


这听起来非常像家庭作业问题,所以我不打算给b
给你一个完整的答案。也许如果你可以更具体地说明

那部分'给你带来麻烦,我们可以帮你解决这个问题。


如果找到平方根?它检查可分性吗?它是否正确使用循环来运行循环?还有其他问题吗?


Tim

-
http://mail.python.org/mailman/listinfo/python-list



" lostinpython" < SH *************** @ hotmail.com>写道:

我在编写一个计算出素数的程序时遇到了麻烦。
有没有人知道如何编写它?我所知道的只是n> 2
如果n和(n)之间没有数字n(包含)均匀分布n。




如何(未经测试):


import sys

导入子流程

primes = subprocess.Popen([" primes",sys。 argv [1],sys.argv [1]],

stdout = subprocess.PIPE).stdout.readlines()

如果素数:

print sys.argv [1],prime

else:

print sys.argv [1],not prime


说真的,这听起来像是家庭作业。谷歌为筛选

of eratosthenes。 BSD素数指的是我在上面使用的程序是用C实现的那个。


如果它不是家庭作业,你老实说这样,那么你应该知道这个领域已经有很多研究,因为

素数在加密应用中非常重要。再一次,google

是一个开始寻找最近关于这个主题的研究的好地方。


< mike

-

Mike Meyer< mw*@mired.org> http://www.mired.org/home/mwm/

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


这是一本书的家庭作业,但不是课堂作业。我是

试图教我自己一些基本的编程之前我必须把它拿到学校的b $ b。如果我对这个主题有足够的了解,我的顾问

会让我放弃介绍。编程并进入介绍。到C ++。

土木工程师对所有这些编程的需求超出了我的范围。我们

必须学习另一种语言来编写我们的CADD软件,我发现它比这更容易。但不用说,我很难解决这个问题。我一直在一个永无止境的循环中结束。


Shanna


Mike Meyer写道:

" lostinpython" ; < SH *************** @ hotmail.com>写道:

我在编写一个计算出素数的程序时遇到了麻烦。
有没有人知道如何编写它?我所知道的只是n> 2如果n和(n)之间没有数字n(包含)均匀分布n。



这个(未经测试)怎么样:

import sys
import子进程

primes = subprocess.Popen([" primes",sys.argv [1],sys.argv [1]], stdout = subprocess.PIPE).stdout.readlines()
如果素数:
print sys.argv [1],prime
否则:
print sys.argv [1],不是素数

说真的,这听起来像是家庭作业。谷歌为eratosthenes的筛子。 BSD素数指的是我在上面使用的程序是在C中实现的。

如果它不是家庭作业,你老老实实,那么
你应该知道这个领域已经有很多研究,因为素数在加密应用中很重要。再次,谷歌
是一个开始寻找最近研究的好地方。

<迈克
-
Mike Meyer< mw * @ mired.org> http://www.mired.org/home/mwm/ <独立的WWW / Perforce / FreeBSD / Unix顾问,请发送电子邮件以获取更多信息。




I''m having trouble writing a program that figures out a prime number.
Does anyone have an idea on how to write it? All I know is that n > 2
is prim if no number between 2 and sqrt of n (inclusivly) evenly
divides n.

解决方案

On 29 May 2005 19:55:32 -0700, lostinpython
<sh***************@hotmail.com> wrote:

I''m having trouble writing a program that figures out a prime number.
Does anyone have an idea on how to write it? All I know is that n > 2
is prim if no number between 2 and sqrt of n (inclusivly) evenly
divides n.
This sounds remarkably like a homework problem, so I''m not going to
give you a full answer. Perhaps if you could be more specific about
which part''s giving you trouble we could help you out with that.

If it finding square roots? is it checking for divisibility? is it
getting the loop to run through correctly? Is it some other problem?

Tim

--
http://mail.python.org/mailman/listinfo/python-list



"lostinpython" <sh***************@hotmail.com> writes:

I''m having trouble writing a program that figures out a prime number.
Does anyone have an idea on how to write it? All I know is that n > 2
is prim if no number between 2 and sqrt of n (inclusivly) evenly
divides n.



How about this (untested):

import sys
import subprocess

primes = subprocess.Popen(["primes", sys.argv[1], sys.argv[1]],
stdout=subprocess.PIPE).stdout.readlines()
if primes:
print sys.argv[1], "prime"
else:
print sys.argv[1], "not prime"

Seriously, this sounds like a homework assignment. Google for "sieve
of eratosthenes". The BSD "primes" program I used in the above is an
implementation of that in C.

If it isn''t a homework assignment, and you''re honestly in such, then
you should know there''s been a lot of research in this area, because
primes are important in cryptographic applications. Once again, google
is a good place to start on looking for recent research on the subject.

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


It is a homework assignment from a book but not for a class. I''m
trying to teach my self some basic programming before I have to take it
in college. If I show enough understanding of the subject, my advisor
will let me forgo Intro. to Programming and go into Intro. to C++.
What civil engineers need with all this programming is beyond me. We
have to learn another language to program our CADD software, which I
find much easier than this. But needless to say, I''m stumped on this
problem. I keep ending up in a never ending loop.

Shanna

Mike Meyer wrote:

"lostinpython" <sh***************@hotmail.com> writes:

I''m having trouble writing a program that figures out a prime number.
Does anyone have an idea on how to write it? All I know is that n > 2
is prim if no number between 2 and sqrt of n (inclusivly) evenly
divides n.



How about this (untested):

import sys
import subprocess

primes = subprocess.Popen(["primes", sys.argv[1], sys.argv[1]],
stdout=subprocess.PIPE).stdout.readlines()
if primes:
print sys.argv[1], "prime"
else:
print sys.argv[1], "not prime"

Seriously, this sounds like a homework assignment. Google for "sieve
of eratosthenes". The BSD "primes" program I used in the above is an
implementation of that in C.

If it isn''t a homework assignment, and you''re honestly in such, then
you should know there''s been a lot of research in this area, because
primes are important in cryptographic applications. Once again, google
is a good place to start on looking for recent research on the subject.

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




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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆