(m mod i) = 0
k = m
1 to m - 1
Next
End If
例如:
Dim m As Integer, i As Integer, j As Integer, k As Integer
Dim a()
m = Val(Text1.Text)
For h = 1 To m
ReDim a(0)
j = 0
k = 0
For i = 1 To h - 1
If h Mod i = 0 Then
k = k + i
j = j + 1
ReDim Preserve a(j)
a(j) = i
End If
Next i
If h = k Then
Print h &"是完数,"
Print h"="
For i = 1 To UBound(a) - 1
Picture1.Print a(i)"+"
Next i
Print a(i)
Else
Print m &"不是完数"
End If
Next h
扩展资料:
(1)所有的完全数都是三角形数。例如:6=1+2+3;28=1+2+3+...+6+7;496=1+2+3+...+30+31;8128=1+2+3…+126+127。
(2)所有的完全数的倒数贺耐都是调和数。例如:1/1+1/2+1/3+1/6=2;1/1+1/2+1/4+1/7+1/14+1/28=2;1/1+1/2+1/4+1/8+1/16+1/31+1/62+1/124+1/248+1/496=2。
(3)可以表示成连续奇立方数之和。除6以外的完全数,都可以表示成连续奇立方数之此拍段和,并规律式增加。例如:28=1³+3^3;496=1^3+3^3+5^3+7^3;8128=1^3+3^3+5^3+……+15^3;33550336=1^3+3^3+5^3+……+125^3+127^3。
参考资料来源:百森誉度百科-完全数
'求完数Dim i, j, sum As Long
Print "链盯丛1000以内的完数:"
For i = 5 To 1000 '棚樱1000以内的完数,最小的完数为6,所以从数字5开始求,以节省计算量则没!
sum = 1 '子因子1不用再求,直接赋予。
For j = 2 To Int(i / 2) '子因子小于所求数的一半
If (i Mod j) = 0 Then sum = sum + j
Next 'j
If i = sum Then Print i '输出完数
Next 'i
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)