|
大概试了下,没检查,看其他老师的代码互相验证吧。
显示有1万多个不重复的7位数,并且对应的7次方和没有重复的。- Sub test7()
- t = Timer
- Dim d As Object, d1 As Object
- Set d = CreateObject("scripting.dictionary")
- Set d1 = CreateObject("scripting.dictionary")
- For i = 1000000 To 9999999
- s = sortNum(i)
- If Not d.exists(s) Then
- d(s) = m
- m = Sqr7(s)
- If d1.exists(m) Then
- Debug.Print "it's the same", d1(m), s
- Exit For
- Else
- d1(m) = s
- End If
- End If
- Next
- MsgBox Timer - t & "_" & d.Count
- Set d = Nothing
- Set d1 = Nothing
- End Sub
- Function sortNum(x)
- Dim ar(9) As String, k
- k = Len(x)
- For i = 1 To k
- s = Mid(x, i, 1)
- ar(s) = ar(s) & s
- Next
- sortNum = Join(ar, "")
- End Function
- Function Sqr7(x)
- For i = 1 To Len(x)
- Sqr7 = Sqr7 + Mid(x, i, 1) ^ 7
- Next
- End Function
复制代码 |
|