2009年4月20日 星期一

尋找完全數

image

'尋找完全數
Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim t1 As Date = Now
        Dim acct As TimeSpan

        Dim str1 = ""
        Dim c = 0
        Dim i
        Dim n = 6
        For n = 1 To 10000
            Dim s = 0
            For i = 1 To Int(n / 2)
                If n Mod i = 0 Then
                    s = s + i
                End If
            Next
            If s = n Then
                c = c + 1
                acct = Now - t1
                str1 = str1 & c & ":" & n & "-->" & acct.TotalSeconds & "sec" & vbNewLine
            End If
        Next n
        MsgBox(str1)
    End Sub
End Class

沒有留言:

張貼留言