作者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
1F:推 q123997788:谢谢你 10/02 23:42
2F:推 presider7859:执行之後未啥卡在 a = CLng(Text1.Text) 12/07 20:16