利用正則判別素?cái)?shù),來(lái)源于網(wǎng)絡(luò),神人!
復(fù)制代碼 代碼如下:
Set regex = New RegExp
regex.Pattern = "^1?$¦^(11+?)\1+$"
For i = 1 To 100
If Not regex.Test(String(i,"1")) Then
WScript.Echo i
End If
Next
看到標(biāo)題你一定會(huì)不屑一顧,枚舉質(zhì)數(shù)誰(shuí)不會(huì)?
復(fù)制代碼 代碼如下:
For i = 1 To 100
For j = 2 To i
If i Mod j = 0 Then Exit For
Next
If j = i Then WScript.Echo i
Next
幾行代碼就能搞定,如此簡(jiǎn)單。那就看看下面這個(gè)程序吧!
復(fù)制代碼 代碼如下:
Set regex = New RegExp
regex.Pattern = "^1?$|^(11+?)\1+$"
For i = 1 To 100
If Not regex.Test(String(i,"1")) Then
WScript.Echo i
End If
Next
用正則表達(dá)式判斷質(zhì)數(shù),神一樣的人物。
來(lái)源:
http://demon.tw/programming/vbs-prime-number.html
http://www.enun.net/?p=533