pascal programming--prime

2007-11-27 2:02 am
怎样用loop找出一個integer 是否prime?以及怎找出prime factors?
只有方法都ok.
更新1:

用哪個loop statement?

回答 (2)

2007-11-27 2:12 am
✔ 最佳答案
只要check下1至target 有幾多個factors..如果得2個factors(1同埋target自己)咁個個數就係prime。

而找prime factor就應該係(1-target內)一個個prime no. generate出黎再試下可唔可以整除到佢。
參考: 自己
2007-11-29 5:27 am
array p[ ]

for (i = 1 to n) check each number, N
{
if N is prime (N mod p[m] != 0, m = 1, 2, 3, ..., m)
add prime to p[m+1]
}

2007-11-28 21:32:23 補充:
找出 prime factorsfirst, generate p[ ] using above methodthen,for (1 to m) {if N mod p[m] = 0, m = 1, 2, 3, ..., m)output p[m]}


收錄日期: 2021-05-03 23:08:15
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20071126000051KK02399

檢視 Wayback Machine 備份