埃拉托斯特尼篩法
Description
埃拉托斯特尼篩法是一種質數篩法,他的運作原理如下。
a) 產生一個陣列,把所有元素初始化為 1 (真)。索引為質數的陣列元素會保持為 1 。所有其他陣列的值最終會被設定為1
b) 由陣列索引 2 開始 (因為 1 不是質數),每一次找到值為 1 的陣列元素,便往陣列後方操作,只要下一個索引是目前所引的倍數,便將其所對應的陣列元素設定為 0。
最後請將陣列元素為 1 者的索引值輸出。
請實作埃拉托斯特尼篩法,判斷 1~999之間的質數,並且印出。
The Sieve of Eratosthenes is a prime number sieve method, and its working principle is as follows.
a) Produce an array, initializing all elements to 1 (True). Array elements with prime indexes remain at 1 . All other array values will eventually be set to 1
b) Starting from array index 2 (because 1 is not a prime number), each time an array element with a value of 1 is found, the operation is performed to the rear of the array. As long as the next index is a multiple of the current index, the corresponding array element is set. Set to 0.
Finally, please output the index value of the array element that is 1.
Please implement the Sieve of Eratosthenes to determine the prime numbers between 1 and 999, and print them out.
Input
無輸入。
none.
Output
請輸出完成埃拉托斯特尼篩法的陣列。
Please output the array that completes the Sieve of Eratosthenes.
Sample Input 1