#include <array.au3>
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
$out = ""
$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' & $pe & '72' & $pe & '72' & $pe & '72' & $pe & '72' & $pe & '72' & $pe & '72' & $pe & '72' & $pe & '72'
$result = _MultiX($result, $p)
$pe = ""
Next
MsgBox(0, "耗时:" & TimerDiff($timer), "1-" & $num & " 相加的数是:" & _RoundX($result)&@CRLF&@CRLF&"未进行四舍五入前的值:"&$result)
Func _MultiX($num1, $num2) ;高精度乘法运算,位数精确到10000位
Local $result[10000], $point
$pointSpace1 = StringInStr($num1, ".")
$pointSpace2 = StringInStr($num2, ".")
If $pointSpace1 Then $point += StringLen($num1) - $pointSpace1
If $pointSpace2 Then $point += StringLen($num2) - $pointSpace2
$num1 = StringReplace($num1, ".", "")
$num2 = StringReplace($num2, ".", "")
$aNum = StringSplit($num1, "")
_ArrayReverse($aNum, 1, UBound($aNum) - 1)
_ArrayDelete($aNum, 0)
If $result[0] == "" Then
$bNum = StringSplit($num2, "")
_ArrayReverse($bNum, 1, UBound($bNum) - 1)
_ArrayDelete($bNum, 0)
Else
ReDim $bNum[1]
For $k = 0 To UBound($result) - 1
If $result[$k] == "" Then ExitLoop
_ArrayAdd($bNum, $result[$k])
$result[$k] = ""
Next
_ArrayDelete($bNum, 0)
EndIf
For $i = 0 To UBound($aNum) - 1
For $j = 0 To UBound($bNum) - 1
$cur = $i + $j
$result[$cur] += $aNum[$i] * $bNum[$j]
If $result[$cur] >= 10 Then
$temp = Mod($result[$cur], 10)
$result[$cur + 1] += Int($result[$cur] / 10)
$result[$cur] = $temp
EndIf
Next
Next
_ArrayReverse($result, 0, UBound($result) - 1)
$sResult = StringReplace(_ArrayToString($result), '|', "")
$temp = StringRight($sResult, $point)
$sResult = StringTrimRight($sResult, $point) & '.' & $temp
Return $sResult
EndFunc ;==>_MultiX
Func _RoundX($num, $n = 0)
$point = StringInStr($num, ".")
If $point <= 0 Then Return $num
$sResult = StringLeft($num, $point + $n + 1)
$aResult = StringSplit($sResult, "")
_ArrayDelete($aResult, 0)
$arrayCur = UBound($aResult) - 1
If $aResult[$arrayCur] >= 5 Then
If $aResult[$arrayCur - 1] <> "." Then
$aResult[$arrayCur - 1] += 1
$aResult[$arrayCur] = 0
$arrayCur -= 1
Else
$aResult[$arrayCur - 2] += 1
$aResult[$arrayCur] = 0
$arrayCur -= 2
EndIf
Else
_ArrayDelete($aResult, $arrayCur)
Return
EndIf
While $arrayCur
If $aResult[$arrayCur] >= 10 Then
$aResult[$arrayCur] -= 10
If $aResult[$arrayCur - 1] == "." Then $arrayCur -= 1
$aResult[$arrayCur - 1] += 1
EndIf
$arrayCur -= 1
WEnd
_ArrayDelete($aResult, UBound($aResult))
If $n == 0 Then _ArrayDelete($aResult, UBound($aResult))
$sResult = StringReplace(_ArrayToString($aResult), '|', "")
Return $sResult
EndFunc ;==>_RoundX