本帖最后由 C.L 于 2010-8-3 22:41 编辑
很有意思的题目,我也写了一个算法,算1-999999999(除去含4和7的数)相加的耗时为 4MS 左右,Input框只能输入数字为9的数,如:99,9999,99999999,输入其他非9组成的数,不保证结果正确local $num = InputBox ('叠加1-999*','只能输入数字9','')
Local $result = ""
local $i,$j
Local $timer = TimerInit ()
for $i=1 to 99
if Not stringregexp($i,"4|7") then
$j=$j+$i
endif
If $i = 9 Then
$one = $j
Else
$two = $j
EndIf
next
$len = StringLen ($num)
If $len < 2 Then
$result = $one
Else
$result = $two
EndIf
$pe = ""
For $i=1 To $len-2
For $j=1 To $i-1
$pe &= "0"
Next
$p = '80.'&$pe&'72'&$pe&'72'&$pe&'72'&$pe&'72'
$result = Round($result * $p)
$pe = ""
Next
MsgBox (0,"耗时:"&TimerDiff ($timer),"1-"&$num &" 相加的数是:"&$result)
|