编程:一个数如果恰好等于它的因子之和,这个数就称为“完数”。例如,6的因数为1,2,3,而6=1+

2024-11-08 01:29:48
推荐回答(1个)
回答1:

Private Sub Command1_Click()

  For i = 1 To 1000

    If is_ws(i) Then

      Print Trim(Str(i)); ": its factors are 1";

      For j = 2 To i \ 2

        If i Mod j = 0 Then Print ","; Trim(Str(j));

      Next j

      Print

    End If

  Next i

End Sub


Function is_ws(n) As Boolean

  s = 0

  For i = 1 To n \ 2

    If n Mod i = 0 Then s = s + i

  Next i

  is_ws = (s = n)

End Function