CSP 找素数

“Problem: To print in ascending order all primes less than 10000. Use an array of processes, SIEVE, in which each process inputs a prime from its predecessor and prints it. The process then inputs an ascending stream of numbers from its predecessor and passes them on to its successor, suppressing any that are multiples of the original prime.”

 

要找出10000以内所有的素数,这里使用的方法是筛法,即从2开始每找到一个素数就标记所有能被该素数整除的所有数。直到没有可标记的数,剩下的就都是素数。下面以找出10以内所有素数为例,借用 CSP 方式解决这个问题。

 

1.2 Hello, World 的革命 · Go语言高级编程 https://chai2010.cn/advanced-go-programming-book/ch1-basic/ch1-02-hello-revolution.html

 

posted @ 2018-08-14 19:05  papering  阅读(122)  评论(0编辑  收藏  举报