Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 工程数学软件 > MATLAB论坛
MATLAB论坛 一切MATLAB相关问题在此讨论。
 
 
主题工具 显示模式
旧 2009-10-09, 14:20   #1
tx1988
初级会员
 
注册日期: 2009-10-09
年龄: 37
帖子: 1
声望力: 0
tx1988 正向着好的方向发展
默认 求助:编写一个找出所有质数的方程

今天老师让用 Sieve of Eratosthenes 这个算法去求出所有的prime numbers。 比如你input 50, 这个方程就会return 所有的prime number。 老师给了指导:
1. Create the list {2, 3, 4, . . . , N}.
2. Set p = 2, the smallest prime number.
3. Delete all multiples of p that are ≤ N.
4. Replace p with the first number of the remaining list that is ≥ p; this number is the next largest prime ≤ N.
5. Repeat steps 3 and 4 until p2 > N.
It is straightforward to check that all the remaining numbers on the list are prime.

也就是先创建一个array,然后从p=2开始,将所有能整除p的数去掉,但是怎么在已经建立好的array里去掉某一项?我是第一次接触这个,能给能给个示范怎么编这个程序?
tx1988 当前离线   回复时引用此帖
 

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 01:57


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.