作者ClubT (風)
看板Visual_Basic
標題Re: 質因數判斷與完全數
時間Mon Oct 1 11:39:03 2007
: 接下來該怎麼寫出裡面因數的質數出來呢?
: 完全數是什麼?該怎麼寫?
: 請求各位大大解惑 謝謝
Private Sub Command1_Click()
Dim a As Long
Dim b As Long
Dim i As Long
Dim j As Integer
a = CLng(Text1.Text)
List1.Clear
b = a
For i = 2 To a
If b Mod i = 0 Then
j = 0
Do While (b Mod i = 0)
j = j + 1
b = b / i
Loop
List1.AddItem (CStr(i) + "," + CStr(j)) 'i是質因數 j是該次方數
End If
Next i
End Sub
完全數這種東西上網找就有了
ex: 6這個數的因數1,2,3,6
扣掉自己就剩1,2,3
如果剩下的因數相加等於本身就是完全數
所以 1+2+3=6 -> 6是完全數
--
我的Blog
http://clubtblog.blogspot.com
我的巴哈小站
http://home.gamer.com.tw/clubt
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.230.127.214
推 q123997788:謝謝你 10/02 23:42
推 presider7859:執行之後未啥卡在 a = CLng(Text1.Text) 12/07 20:16