2009年5月5日 星期二

求質因數

image

'求質因數
Public Class Form1
    Dim i, j, k
    Dim str1, str2
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim n() = {24, 36, 55, 110, 2300}
        For k = 0 To n.Length - 1
            str1 = n(k) & "->"
            For i = 1 To n(k)
                If n(k) Mod i = 0 Then
                    Dim c = 0
                    For j = 1 To i
                        If i Mod j = 0 Then c = c + 1
                    Next
                    If c = 2 Then str1 = str1 & i & Space(3)
                End If
            Next
            str2 = str2 & str1 & vbNewLine
        Next
        MsgBox(str2)
    End Sub
End Class

沒有留言:

張貼留言