以下是引用fyupeng在2006-7-14 13:55:00的发言:
关键还在于生成的两个数的分别判断,因为4按代码应该只能拆成2、2,不能拆成0、4或1、3,因为4加1或减1还是会被5整除,不符合条件(1-1 mod 5=0,1也不行)。只要两个数判断成功,就不会出现0。
那是加一减一都不能被5整除, 你再测试一下
Function NumMod(intNum As Integer) As Boolean
Dim RadNumA As Integer
Dim RadNumB As Integer
Dim TF As Integer
TF = 0
If ((intNum + 1) Mod 5 = 0) Or ((intNum - 1) Mod 5 = 0) Then
Do Until TF = 1
RadNumA = Int((intNum * Rnd) + 1)
RadNumB = intNum - RadNumA
If ((RadNumA + 1) Mod 5 <> 0 And (RadNumB + 1) Mod 5 <> 0) And ((RadNumA - 1) Mod 5 <> 0 And (RadNumB - 1) Mod 5 <> 0) Then
TF = 1
NumMod = True
Debug.Print RadNumA
Debug.Print RadNumB
End If
Loop
Else
NumMod = False
End If
End Function
[此贴子已经被作者于2006-7-14 14:18:03编辑过]
|