1using
system;
2using
system.collections;
3using
system.collections.generic;
4using
system.componentmodel;
5using
system.data;
6using
system.drawing;
7using
system.linq;
8using
system.text;
9using
system.threading.tasks;
10using
system.windows.forms;
1112
namespace
bitarraych.algo //
構造器
17private stringbuilder convertbits(int val)
29return
bitbuffer;
30 } //
二進位制轉化器,進int,出string
3132
public
static
void intarraytobitarrayexp() ;
63 bitarray bitvalues = new bitarray(values.select(x => x >= 0
).toarray());
64foreach (bool bitvalue in
bitvalues)
65console.writeline(bitvalue);
66console.readkey();
67 }//
intarraytobitarrayexp by lambda表示式
6869
private
void btnprime_click(object sender, eventargs e) ;
74 bitarray bitvalues = new bitarray(values.select(x => x >= 0
).toarray());
75#endregion 取得使用者輸入的資料並且轉化成二進位制數()
7677
#region 分析已經生成的質數表
78 bitarray bitset =bitvalues;
79buildsieve(bitset);
80if (bitset.get(value) != false
)81 lblprime.text = (value + "
is a prime number.");
82else
83 lblprime.text = (value + "
is not a prime number.");
84#endregion
85 }//
取得使用者輸入的資料並且轉化成二進位制數() 分析已經生成的質數表
8687
private
void buildsieve(bitarray bits)
123 }//
userdata二進位制數 的長度
124#endregion
125126 txtprimes.text =primes;
127 }//
取得使用者輸入的資料並且轉化成二進位制數() 制定素數** 輸出素數**
用 BitArray 來編寫埃拉託斯特尼篩法
using system using system.collections using system.collections.generic using system.componentmodel using system.data using system.drawing using system...
埃拉託色尼篩演算法
功能 用來產生乙個不大於給定整數n的連續質數序列 演算法 sieve n 實現 埃拉託色尼的篩子 輸入 乙個正整數 2 輸出 包含所有小於等於n的質數的陣列l for p 2 to n do a p p a p 表示陣列 for p 2 to do 表示向下取整函式,即求捨去小數部分後的整數值 if...
埃拉託色尼篩選法
埃拉託色尼篩選法 the sieve of eratosthenes 簡稱埃氏篩法,是古希臘數學家埃拉託色尼 eratosthenes 提出的一種篩選法。是針對自然數列中的自然數而實施的,用於求一定範圍內的質數。埃氏篩法步驟編輯 1 先把1刪除 現今數學界1既不是質數也不是合數 2 讀取佇列中當前最...