Calculation of large numbers (3)

zhaozj2021-02-16  60

The following algorithm is based on http://www.9cbs.net/develop/edit.asp?id=28308, which is more than 10% from it:

Sub CalcFactorial (byval n as integer) Dim xys () AS INTEGER, X () AS Integer, y () AS integer, result () AS STRING, I As Long, J AS Long, K As Long, Temp As long, Stimer As Doubleif N <0 THEN EXIT SUBREDIM X (1) Redim Xys (1) x (1) = 1xys (1) = 1k = 1stimer = Timerdo While K <= n

Temp = len (CSTR (K)) Redim Y (1 to Temp) for i = 1 to Tempy (i) = VAL (MID (K, Temp 1 - i, 1)) Nextredim Xys (1 to Ubound (x) Ubound (Y)) for i = 1 to Ubound (x) for j = 1 to Ubound (y) XYS (i j - 1) = XYS (i j - 1) x (i) * y (j NEXTNEXTFOR I = 1 to Ubound (x) ubound (y) - 1TEMP = Xys (i) / 10XYS (i) = xys (i) MOD 10XYS (i 1) = XYS (i 1) TempNext

x = xysif x (ubound (x)) = 0 THEN Redim preserve x (1 to Ubound (x) - 1) k = k 1loopredim Result (1 to Ubound (x)) for i = 1 to Ubound (x) Result (i) = x (Ubound (x) 1 - i) Next

Factorial = Join (Result, ") Debug.print K - 1 &"!: Time "; Timer - Stimer &" Sales, Results "& Ubound (x) &" Bit "'debug.print factorialerase x () ERASE Y () Erase Xys () ERASE Result () End Sub

Private sub fascist1_click () for i = 1 to 9calcfactorial i * 100NextFor i = 1 to 10calcfactorial i * 100Next

End Sub

Result output:

转载请注明原文地址:https://www.9cbs.com/read-23725.html

New Post(0)