Calculation of large numbers (six)

zhaozj2021-02-16  59

It is always difficult to improve the multiplication calculation of the most intensive intensity: (http://dev.9cbs.net/develop/article/28/28306.shtm, http://dev.9cbs.net/ Develop / article / 28 / 28308.shtm, http: //dev.9cbs.net/develop/Article/28/28432.shtm, http: //dev.9cbs.net/develop/Article/28/28641.shtm)

Suddenly thinking about today

N! = 1 * 2 * 3 * .... * n → lg (n!) = lg (1 * 2 * 3 * .... * n) = lg (1) LG (2) LG ( 3) .. lg (n) → n! = 10 ^ (LG (1) LG (2) LG (3) .. LG (n))

Considering that when the N is large, there is no practical significance of the output specific results, and the code is written as follows:

Sub calcfactorial (ByVal num As Long, Optional ByRef POWER As String, Optional ByRef FIRSTNUM As String) Dim I As Long, TEMP As Double, temp2 As Long, STIME As SingleTEMP = 0temp2 = 0STIME = TimerFor I = 1 To numTEMP = TEMP LOG (i) / log (10) if Temp> 1000000 ThenTemp2 = TEMP2 1TEMP = Temp - 1000000 00d ifnextpower = Format (INT 1), "000000") Temp = Temp - Val (Power) Power = Temp2 & Powerif Val (Power) <10 ^ 6 Then Power = Val (Power) firstnum = left (10 ^ (Temp), ".", "", 10) Debug.Print Right (Space (9) & Num, 9 ) & "!: Time" & Right (Space (8) & format (Timer - Stime, "0.00000"), 8) & "Second, Results" & Right (Space (10) & Power, 10) & ", Top 10 "& dimstNumend Sub

PRIVATE SUB Command1_Click () DIM I As Long, J AS Longfor J = 2 to 7for I = 1 to 10calcFactorial i * 10 ^ jnextdebug.printnextend Sub

Output results:

'100! : When used at 0.00000 seconds, 158 points, the first 10 is 9332621544 '200! : Use 0.00000 seconds, 375 results, the top 10 is 7886578673 '300! : When used at 0.00000 seconds, the result is 615 bit, the top 10 is 30605122 '400! : When used at 0.00000 seconds, the result is 869 bits, the top 10 is 6403452284 '500! : When used at 0.00,000 seconds, the result is 1135 bit, the top 10 is 1220136825 '600! : When used at 0.00000 seconds, 1409 points, the top 10 is 126572316 '700! : When used in 0.01563 seconds, the result is 1690 bits, the top 10 is 2422040124 '800! : When used at 0.00000 seconds, the result is 1977, the top 10 is 7710530113 '900! : When used at 0.00000 seconds, the result is 2270 bits, the top 10 is 6752680220 '1000! : When used at 0.00000 seconds, the result is 2568 bits, the top 10 is 4023872600 '' 1000! : When used at 0.00000 seconds, the result is 2568 bit, the top 10 is 4023872600 '2000! : Use 0.01563 seconds, 5736 bits, the top 10 is 3316275092 '3000! : When used at 0.00000 seconds, 9131 results, the top 10 is 4149359603 '4000! : When used at 0.00000 seconds, the result is 12674 bit, the top 10 is 1828801951 '5000! : When used at 0.00000 seconds, the result is 16326 bits, the top 10 is 4228577926 '6000! : When used in 0.01563 seconds, the result is 20066 bit, the top 10 is 268399765 '7000! : When used at 0.00000 seconds, the result is 23,878 bits, the top 10 is 8842007956 '8000! : When used at 0.00000 seconds, the result is 27753 bit, the top 10 is 5184181060 '9000! : When used in 0.01563 seconds, the result is 31682 bits, the top 10 is 809589986 '1000! : Use 0.00000 seconds, 35660 bits, the top 10 is 2846259680 '' 1000! : Use 0.00,000 seconds, 35660 bits, the top 10 is 2846259680 '20000! :

It is 0.00000 seconds, and the result is 7,7338, the top 10 is 1819206320 '30000! : When used in 0.04688 seconds, the result is 12,1288 bit, the top 10 is 2759537248 '40000! : When used at 0.01563 seconds, the result is 166714 bit, the top 10 is 2091692420 '5000! : When used at 0.03125 seconds, the result is 213,237 bits, the top 10 is 3347320501 '60000! : When used in 0.01563 seconds, the result is 260,635 bits, the top 10 is 1564137704 '70000! : When used in 0.03125 seconds, 308,760 bits, the top 10 is 1176812415 '80000! : When used in 0.03125 seconds, the result is 357507 bit, the top 10 is 309722262 '90000! : When used at 0.03125 seconds, the result is 406799 bit, the top 10 is 1580119155 '100000! : When used in 0.04688 seconds, the result is 456,574 bits, the top 10 is 2824229408 '100000! : Use 0.04688 seconds, the result 456574 bit, the top 10 is 2824229408 '200000! : When used in 0.10938 seconds, the result is 973351 bit, the top 10 is 1420225354 '300000! : 0.12500 seconds, 1512,852 bits, the top 10 is 1477391532 '400000! : When used at 0.23438 seconds, the result is 2067110 bits, the top 10 is 2534486091 '500000! : When used in 0.21875 seconds, the result is 2632342 bits, the top 10 is 1022801596 '600000! : When used in 0.35938 seconds, the result is 3206,318, the top 10 is 2234878214 '700000! : When used at 0.40625 seconds, the result is 3787566 bit, the top 10 is 6491076363 '800000! : When used at 0.43750 seconds, the result is 4375040 bits, the top 10 is 5684678869 '900000! : When used in 0.54688 seconds, the result is 4967957 bit, the top 10 is 3990191306 '1000000! : Use 0.54688 seconds, 5565709 bits, the top 10 is 8263932189 '100000! : Use 0.51563 seconds, 5565709 bits, the top 10 is 8263932189 '2000000! : When used 1.10938 seconds, the result is 11733475 bit, the top 10 is 3776821110 '3000000! : When used, 1.56250 seconds, the result 18128484 bit, the top 10 is 9038572324 '4000000! :

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

New Post(0)