| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 31028 人关注过本帖
标题:各位老师好!求助编辑一个大整数的快速乘除法可调用程序
只看楼主 加入收藏
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
我们可以将大整数对拆为两个部分。
即a和b相乘就可以写为:a * b = {  a1 * 10^(n1/2)   + a0  }  *  {  b1 * 10^(n2/2)  +  b0 }

展开后整理得: a  *  b =  a1*b1 * 10^[ (n1+n2)/2 ]   +  a1*b0 * 10^(n1/2)  +   a0*b1 * 10^(n2/2)  + a0*b0 ;这样就容易递归的来求a * b,如果你嫌分解后的数还太大,就可以继续分解
实现方法:我们定义一个支持方法,用于在结束递归时(在本例中,我定义有一个数是1位时结束递归,直接用普通乘法)计算两个字符串的乘积(为了表示大数,用字符串来接受参数)。有 了这个支持方法,分治递归实现两个大数乘法的实现
2021-03-31 18:43
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
51750801837147361345408953922231823615475578427966187002956389087112242842559611794590895524485015222232340190036677951157401229518412775512617768569186939216558814320044037671525512763073762127357272238470370174050144130962253437215369727381909754581075278888137687950749577751967083233227932391898438489520107788418593104216764745143648165875043861634459264809523254076330115365651752264033578829280651927862062277153553168278640509846511729608378923480331705134467105387853440058108864733429085916392927954109944314725590758950098556991513109760871599045355054258610189920009222629391227784118536578933067532162200768112408111142115021110731900107445187734955403922470144187293970602024056652942406064101184615113779243566842311336047149767396006622923831778833173731302325162741660053390002572456069410383734906953419854919650114722834689335022576764661864630532595250136417800041415827379233503655173380741283758557001102498493237113089198106283487003030225058520047964863929279622015825870972146222540614667928697270131499340362072956956518213266361286372027834000838185920579641835952404678850816456467012890793914108776148483471455515695596694573035435841962871983614397882366460940068418989292218104650923374259244879331938925143014431488635252724366437874702141802712286424754174951797598162531093933772708024046029028652425912112434874797404878317364682580259997737809632860143160557722236459697738869857870982308547756781808568834445404196611833859447257611721058384661943492980180884154939581533269700568975940675513953240040220315659784214936947443784598154082110443748171557676558299300252057475022409541083454882202785077569281268346332901357829843950754331120530978456454396022570647840977328115888711408099894489014427119253061839770890965114853246067272044090282103668762164047374624856119676063310166566519499552342907590495696658359542582469176737197423550084705962160477441546453931948920780829433665262356431973422034925001341330921812806939990688094288773216182971976433480031438271163051341645350474631300965486818841553843112688792803367397276204832936049162335586140151875524537720425345701193713093955432559579831822084761702059241698184717469616732582600658006352069963017377661059372648121969448644394344799369193952197519795756182552461838014896498816263546256621347748100920475049252091842372001283217811864786225692344297842649982716736752004086642881662614773154743879410328420184057019873899911520017723788801*
51750801837147361345408953922231823615475578427966187002956389087112242842559611794590895524485015222232340190036677951157401229518412775512617768569186939216558814320044037671525512763073762127357272238470370174050144130962253437215369727381909754581075278888137687950749577751967083233227932391898438489520107788418593104216764745143648165875043861634459264809523254076330115365651752264033578829280651927862062277153553168278640509846511729608378923480331705134467105387853440058108864733429085916392927954109944314725590758950098556991513109760871599045355054258610189920009222629391227784118536578933067532162200768112408111142115021110731900107445187734955403922470144187293970602024056652942406064101184615113779243566842311336047149767396006622923831778833173731302325162741660053390002572456069410383734906953419854919650114722834689335022576764661864630532595250136417800041415827379233503655173380741283758557001102498493237113089198106283487003030225058520047964863929279622015825870972146222540614667928697270131499340362072956956518213266361286372027834000838185920579641835952404678850816456467012890793914108776148483471455515695596694573035435841962871983614397882366460940068418989292218104650923374259244879331938925143014431488635252724366437874702141802712286424754174951797598162531093933772708024046029028652425912112434874797404878317364682580259997737809632860143160557722236459697738869857870982308547756781808568834445404196611833859447257611721058384661943492980180884154939581533269700568975940675513953240040220315659784214936947443784598154082110443748171557676558299300252057475022409541083454882202785077569281268346332901357829843950754331120530978456454396022570647840977328115888711408099894489014427119253061839770890965114853246067272044090282103668762164047374624856119676063310166566519499552342907590495696658359542582469176737197423550084705962160477441546453931948920780829433665262356431973422034925001341330921812806939990688094288773216182971976433480031438271163051341645350474631300965486818841553843112688792803367397276204832936049162335586140151875524537720425345701193713093955432559579831822084761702059241698184717469616732582600658006352069963017377661059372648121969448644394344799369193952197519795756182552461838014896498816263546256621347748100920475049252091842372001283217811864786225692344297842649982716736752004086642881662614773154743879410328420184057019873899911520017723788801=
2678145490787694710138406683675886762424440504352140852415040477225326000647575114434084000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000048834936179488708027435471556408008440453443428926779725245378240242156111594471823310476577367738661644035731268602062638551083913198940248726780437308391759208187712621288584222894315603010609776256047808203862393934077378322284212996836157946999711091192615345115644564888145602118726225574426254611145656509862440059177850469882535839456536039466435887936245004514758161740268485238639890789236999197352641214190642419864819143872302633183381508060449719040910078119545928583104878680100374223404979294439623863053936852460325863660352138953464283864433479288258329615894013575436244909620398852593573959165209852146723195868414819450095293166474419246068624792251500158729313074813990754243002187726402788255875035147805506073557109594514459440946575807793237757285337705966318084700125854763286763044715974271042543210431566104080946423997787549312368322741085681737642202484344855770671575251802263932602238206558927521452296283997708735179255379729870437018144311078653656921356179379717255889408012373548693171269093189347911767572936354646182280905744653428336130203271833375892051912174249364781089867737031174688851723660162503604698668932069480617343408549167594757806847833186692417853509277050942119328203621782210854822594690811434363298309615524303568070355581209122962278030277005774637857956924214246646048987469444447091104070552021471480435227573710497254610554360378934212162465404707794167300382645889282806308095180237562057359674243409733244490831931049344772061654219722274991982817003747530654442293923699611492166208868103074728942943014030254660718267076074671151915772952154978453283321139817502191891451428025074888093137857848155937369023472576807612843066939653358993279349066730708502953804648726711760241371145448021361674713705239201650905644769500219293676896152881383773233182249705584680154888245917843937168667799346858885231837945440618024916511248385931440602958543262820501974063791697789527953759491166283169241407966207226163326191460372450932044051370230543608342821033473404914121829529590454279123910485652677864764230217322262551731228103618793249634768108819504251685204021169682940059714297096572968426365178022098712842526881685269892119380518399424717940517253783459916522217208335231942121084925515180217597771274533784487863804095664249547028094536853234436994416010805830376423230834237011274973707414073049913128257517631098768469662377613580085684857279852078064471049808506001390599318115347850573917152685295145963307264334360805483089392131468488840686512613378918292927803491310964968936474151927494956717767502696756499701517208075109262341934406482502331252818716359969922837306785955242419168770627555010174863351154399341242232233457270379687646890750322395716028712265386686817398796239601435251412889109101495271260695793700702337565433556822121715587814914939546416648017852596142359775827940200354105961365260177354558828192092060413841135293304399814038242816749559445772646279886702196918742806197182349524180958623098344946102480125559171120395122740471842099684558604610884822932111216853199074776768007834918405075062413588221381655391315218841623755080481394102212121558474742195640527808393537523718723670310899836508493992550359882572122454653849215887390745287805914772137232080736008158427628303158121064565553689542532345804644528894658939608887377827279143521098113972355174011373557722549030347195840504769574273209629932310751597503171061407825884615518048223367691090630514247144551887594035108601695983333346992370597394903524517486860124514674041602443235365127328501568418345710373964098444164115834244922460261107344368735191596460368487577255813303774733776118156247268922022261526312955094802502399373148630398507364969437754278741104640643252194850037020750701584466172422413338145287861330420159965918633476636052486699575826695761237124113609505375040106431777807918125177560371763998256641199099470550367480564755215688490216099359333978962180941400125284442753236570011853188634389108771384375821796093487315084111076120381220996094283323592417209413726042663812262109542726015282249841696703018567110070543728288507529128597875095924358528852936267515439839426131679670901276802163050750126098369347636561857524451706642903292420955569321801425613100890505478610472357490956601092255246041466554317966802293184444182860432246086828700527914016101165025398543989010693124385714424358993377228796856721936384973767950035593026761869617390736082038181438549807436450160416570479922617865403993903012803583520069135616888167827943793870186486907068445有4888位,用时295.377秒(这是由分治法结合我的模仿手工计算的大数乘法程序,做的程序,合4.92295分钟,太浪费时间了,是把300位当一位数做乘法的,可能是我的大数加法和减法程序太慢了,需要改进程序,或者把5000位当作一位做乘法试试,再说吧)
2021-04-01 01:08
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
还是把这个代码发一下吧,效率不高,效率太低了:

Private Sub Command1_Click()
Dim a, B
Dim ja(), jb()
a = Trim(Text1): B = Trim(Text2): a3 = a: b3 = B
ts = Timer
If Len(a) < Len(B) Then
a = String(Len(B) - Len(a), "0") & a
B = B
Else
a = a
B = String(Len(a) - Len(B), "0") & B
End If
x = Len(a) \ 300: Y = x + 2
sb = Y * 2
a = String(Val(sb * 300 - Len(a)), "0") & a
B = String(Val(sb * 300 - Len(B)), "0") & B
x = sb / 2
ReDim ja(1 To x): ReDim jb(1 To x)
For I = 1 To x
ja(I) = Mid(a, 600 * I - 599, 600)
jb(I) = Mid(B, 600 * I - 599, 600)
Next
For i1 = 1 To x
a1 = Mid(ja(i1), 1, 300): a2 = Mid(ja(i1), 301, 300)
For i2 = 1 To x
B1 = Mid(jb(i2), 1, 300): b2 = Mid(jb(i2), 301, 300)
C1 = MbC(Trim(a1), Trim(B1)): C2 = MbC(Trim(a2), Trim(b2))
c3 = MPC1(Trim(a1), Trim(a2)): c4 = MPC1(Trim(B1), Trim(b2))
c5 = MbC(Trim(c3), Trim(c4))
D1 = MPC(Trim(c5), Trim(C1)): D1 = MPC(Trim(D1), Trim(C2))
D2 = MPC1(Trim(C1) & String(600, "0"), Trim(D1) & String(300, "0"))
D2 = MPC1(Trim(D2), Trim(C2))
d3 = MPC1(Trim(d3) & String(600, "0"), Trim(D2))
Next
D4 = MPC1(Trim(D4) & String(600, "0"), Trim(d3))
Next
D4 = qqdl(Mid(D4, Len(D4) - Len(a3) - Len(b3) + 1))
Text3 = D4 & "有" & Len(D4) & "位,用时" & Timer - ts & "秒"
End Sub

Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""

End Sub

Public Function MbC(D1 As String, D2 As String) As String
Dim x, Y ';两数长度
x = Len(D1) \ 4: Y = Len(D2) \ 4
d3 = String(4 * x + 4 - Len(D1), "0") & D1
D4 = String(4 * Y + 4 - Len(D2), "0") & D2
x = x + 1: Y = Y + 1
Dim a() As String
ReDim a(4 To 4 * x + 4 * Y, 4 To 4 * Y)
Dim I, J, C1, C2, CJ, JW, s, t
For J = 4 * Y To 4 Step -4 ';D2
JW = 0 ';进位清0
C2 = Mid(D4, J - 3, 4) ';每位数
For I = 4 * x To 4 Step -4 ';D1
C1 = Mid(d3, I - 3, 4) ';每位数
CJ = Val(C1) * Val(C2) + JW ';计算乘积
c = I + J: r = 4 * Y + 4 - J
a(c, r) = String(4 - Len(CJ Mod 10000), "0") & CJ Mod 10000 ';本位
JW = CJ \ 10000 ';进位
Next
a(c - 4, r) = JW
Next
Dim B() As String
ReDim B(1 To x + Y)
JW = 0
For s = x + Y To 1 Step -1
Bit = JW
For t = 1 To Y
Bit = Bit + Val(a(4 * s, 4 * t))
Next
B(s) = String(4 - Len(Bit Mod 10000), "0") & Bit Mod 10000
JW = Bit \ 10000
Next
If B(1) > 0 Then
MbC = Val(Left(MbC, 5)) & Mid(MbC, 6) & B(1)
Else
MbC = Val(Left(MbC, 5)) & Mid(MbC, 6)
End If
For s = 2 To x + Y
MbC = Val(Left(MbC, 5)) & Mid(MbC, 6) & B(s)
Next
End Function

'该程序已经做了修改,是模仿手工计算的程序,采用4位一组,在位数少于5000的时候,此程序居然比快速傅里叶变换的乘法还快!

Public Function MPC1(D1 As String, D2 As String) As String 'jiafa
  Dim x, Y, JW '两数长度

If Len(D1) >= Len(D2) Then
  D4 = String(Len(D1) - Len(D2), "0") & D2
  d3 = D1
  Else
  D4 = D2
  d3 = String(Len(D2) - Len(D1), "0") & D1
  End If
  x = Len(d3) \ 8: Y = Len(D4) \ 8
  If 8 * x < Len(d3) Then
  d3 = String(8 * x + 8 - Len(d3), "0") & d3
  D4 = String(8 * Y + 8 - Len(D4), "0") & D4
  x = x + 1: Y = Y + 1
  Else
  x = x: Y = Y
  d3 = d3: D4 = D4
  End If
  Dim a() As String, B1() As String, C1() As String, E1() As String
  ReDim a(1 To x)
  ReDim B1(1 To Y)
  ReDim C1(1 To x)
  ReDim E1(1 To x)
  Dim I, J, C2, CJ
  For J = Y To 1 Step -1 'D2
  JW = 0 '进位清0
  B1(J) = Mid$(D4, J * 8 - 7, 8) '每位数
For I = x To 1 Step -1  'D1
     a(I) = Mid$(d3, I * 8 - 7, 8) '每位数
   C1(I) = Val(a(I)) + Val(B1(I)) + Val(JW) '计算jia
   If Len(C1(I)) < 8 Then
   C1(I) = String(8 - Len(C1(I)), "0") & C1(I)
   Else
   C1(I) = C1(I)
   End If
     JW = Left(C1(I), Len(C1(I)) - 8)
     E1(I) = Right(C1(I), 8)
    Next
    Next
    For r = 1 To x
    If JW = 0 Then
    MPC1 = MPC1 & E1(r)
    Else
    jc = jc & E1(r)
    MPC1 = JW & jc
    End If
    Next
   MPC1 = qqdl(Trim(MPC1))
  End Function
  
  Public Function MPC(D1 As String, D2 As String) As String ';jianfaqi
Dim x, Y ';两数长度
If Len(D1) >= Len(D2) Then
D4 = String(Len(D1) - Len(D2), "0") & D2
d3 = D1
Else
D4 = D2
d3 = String(Len(D2) - Len(D1), "0") & D1
End If
x = Len(d3): Y = Len(D4)
Dim a() As Integer, B1() As Integer, C1() As Integer, E1() As Integer
ReDim a(1 To x)
ReDim B1(1 To Y)
ReDim C1(1 To x)
ReDim E1(1 To x)
Dim I, J, C2, CJ, JW
For J = Y To 1 Step -1 ';D2
JW = 1 ';yu jie weichuzhi
B1(J) = Mid(D4, J, 1) ';每位数
For I = x To 1 Step -1  ';D1
   a(I) = Mid(d3, I, 1) ';每位数
   C1(I) = 10 + a(I) - B1(I) - 1 + JW ';计算jia
   JW = C1(I) \ 10
   E1(I) = C1(I) Mod 10
  Next
  Next
  For r = 1 To x
  MPC = MPC & E1(r)
  For I = 1 To Len(MPC)
    If Not Mid(MPC, I, 1) = "0" Then
        Exit For
    End If
Next
strtmp = Mid(MPC, I)
  If Len(strtmp) = 0 Then
  MPC = "0"
  Else
MPC = strtmp
End If
  Next
  
  
End Function

  
  Private Function qqdl(sa As String) As String

  
  For I = 1 To Len(sa)
    If Not Mid(sa, I, 1) = "0" Then
        Exit For
    End If
Next
strtmp = Mid(sa, I)
  If Len(strtmp) = 0 Then
  qqdl = "0"
  Else
qqdl = strtmp
 End If
End Function
2021-04-01 02:13
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
51750801837147361345408953922231823615475578427966187002956389087112242842559611794590895524485015222232340190036677951157401229518412775512617768569186939216558814320044037671525512763073762127357272238470370174050144130962253437215369727381909754581075278888137687950749577751967083233227932391898438489520107788418593104216764745143648165875043861634459264809523254076330115365651752264033578829280651927862062277153553168278640509846511729608378923480331705134467105387853440058108864733429085916392927954109944314725590758950098556991513109760871599045355054258610189920009222629391227784118536578933067532162200768112408111142115021110731900107445187734955403922470144187293970602024056652942406064101184615113779243566842311336047149767396006622923831778833173731302325162741660053390002572456069410383734906953419854919650114722834689335022576764661864630532595250136417800041415827379233503655173380741283758557001102498493237113089198106283487003030225058520047964863929279622015825870972146222540614667928697270131499340362072956956518213266361286372027834000838185920579641835952404678850816456467012890793914108776148483471455515695596694573035435841962871983614397882366460940068418989292218104650923374259244879331938925143014431488635252724366437874702141802712286424754174951797598162531093933772708024046029028652425912112434874797404878317364682580259997737809632860143160557722236459697738869857870982308547756781808568834445404196611833859447257611721058384661943492980180884154939581533269700568975940675513953240040220315659784214936947443784598154082110443748171557676558299300252057475022409541083454882202785077569281268346332901357829843950754331120530978456454396022570647840977328115888711408099894489014427119253061839770890965114853246067272044090282103668762164047374624856119676063310166566519499552342907590495696658359542582469176737197423550084705962160477441546453931948920780829433665262356431973422034925001341330921812806939990688094288773216182971976433480031438271163051341645350474631300965486818841553843112688792803367397276204832936049162335586140151875524537720425345701193713093955432559579831822084761702059241698184717469616732582600658006352069963017377661059372648121969448644394344799369193952197519795756182552461838014896498816263546256621347748100920475049252091842372001283217811864786225692344297842649982716736752004086642881662614773154743879410328420184057019873899911520017723788801*
51750801837147361345408953922231823615475578427966187002956389087112242842559611794590895524485015222232340190036677951157401229518412775512617768569186939216558814320044037671525512763073762127357272238470370174050144130962253437215369727381909754581075278888137687950749577751967083233227932391898438489520107788418593104216764745143648165875043861634459264809523254076330115365651752264033578829280651927862062277153553168278640509846511729608378923480331705134467105387853440058108864733429085916392927954109944314725590758950098556991513109760871599045355054258610189920009222629391227784118536578933067532162200768112408111142115021110731900107445187734955403922470144187293970602024056652942406064101184615113779243566842311336047149767396006622923831778833173731302325162741660053390002572456069410383734906953419854919650114722834689335022576764661864630532595250136417800041415827379233503655173380741283758557001102498493237113089198106283487003030225058520047964863929279622015825870972146222540614667928697270131499340362072956956518213266361286372027834000838185920579641835952404678850816456467012890793914108776148483471455515695596694573035435841962871983614397882366460940068418989292218104650923374259244879331938925143014431488635252724366437874702141802712286424754174951797598162531093933772708024046029028652425912112434874797404878317364682580259997737809632860143160557722236459697738869857870982308547756781808568834445404196611833859447257611721058384661943492980180884154939581533269700568975940675513953240040220315659784214936947443784598154082110443748171557676558299300252057475022409541083454882202785077569281268346332901357829843950754331120530978456454396022570647840977328115888711408099894489014427119253061839770890965114853246067272044090282103668762164047374624856119676063310166566519499552342907590495696658359542582469176737197423550084705962160477441546453931948920780829433665262356431973422034925001341330921812806939990688094288773216182971976433480031438271163051341645350474631300965486818841553843112688792803367397276204832936049162335586140151875524537720425345701193713093955432559579831822084761702059241698184717469616732582600658006352069963017377661059372648121969448644394344799369193952197519795756182552461838014896498816263546256621347748100920475049252091842372001283217811864786225692344297842649982716736752004086642881662614773154743879410328420184057019873899911520017723788801=
2678145490787694710138406683675886762424440548647327525594133873038347266950777818028529804877891353347244255046176220880989519574806598935727647635506939520211209794328712328126947740602255036264392628020291100698432900022333877728824270241063030019536831205264726059774673235680796770108334187808344470141093691232926021244583649747591446066921535333854157441330339217364515328375889937313870826987520723914810358707312468857074455945610038118763873992681688857200178452843740327143990247797893489008808544535536081089994800692174759199578596435124153437689121057209523619989593900355037400039597165241729693472001589594642879166693443994939359639600558001937547209387175085119128575833396037478944824322315197771750730768383267287661855880237549141571520374996029107650341071074081501632143441365461865431362023790463469688071768208320226561675630348708531708110373889241713511809029065048200924851629507265095151843687852114948736130517024578482059771284515915597919026074110811882700307150650858080695566672584075215926450360584738705106755945308199980660478183563586945902705730231409948938478910176292179410952310592864745025373902249844607078729230098512959498522851990040833671698873183076996740726479481352429756295966452788332789259316653805673821716832204368483794501474641036177256005810416507649770210480747056764697918800240201155395628561684853684747063434500664449114760179367086926249813006056735202795763742271472136500817313178050955623517148960973128433455798444839070215800699075256371341531892841721456473301085595261371522078416420399702683504171019191363372883472415693921509069484448792009627325245658854979159002549542769741504596589556474585723101403486046952706847309188488390899096649210853675228464611999630360164703837131620319658277117300208326944026347808645954842782309633205645471959842390075986572806483755223497552549948718545978420793425036666212191832327909389117021539426917904222971515424022606157676379417252939026404363841301595348953340657745965591468370831371449860774296757556463049237248472613472436666799615694672489600751763956185893123579218797539971253828850163437053164723845196089466298000486042246621634263064752906475198879616484926366053597071510886820878425907736453843197228282179943365206039514850477377542684361730162273246709577442085159313947668552462343596819299335060863266863059421286080919061657175757802930378698062290163092494909661982639303946271889619023417245433500782685534406291391527022657608608130680134939380126048353657648559735671562230714451258764762350451448379438849319710473631625533527602085050858633346936315115309333355986556546113134787213610042970405680162084678021281774169131725296977361816657904233850711837826724976507876061043779177845550646612327663283839673950405472039432309339110648301347672597370034346896334064135099613033528785924976781865447506814375627647103020761819104412269362847848884053177378762432543285984193091289854949394023586451139393716370633759317698908834326333339634557238526607966375935960004339535161203546369910853171524516945554862019134684985868547068709986010719120259421723270478586992153989283736650948010894951434857207445141886625290777550599700738909777829412358941157674866550887608199469723859806486384262574182811908513849905040209776132986875560077482527819093584150609347560543627976011009349905362597935257895287412087233810106693141683912683308201407373637490835862452911394718399632093441745957478079754723679119343225931665785380948807114301164623717144211285944154289093317610519159281033583963015810556464180819928345256832572962092994993950655913067768151113345566231088759030148164710287289335782462899525700500822021472132532771242198844498579102733028256523810973405350508253183399668290339844052874956694050028526577775764032598023622192221226501334606994447870277619118208162133562541678250491647671042612088902952091163094215645902682086024337098910110924115381788866213335441814530141911754446270296630426675020592640816713810936850961517475097707179713115856513919631998747192606018612535436009162735908155778165736923393260822217415131632296810207091918499370220533980666393617256227781299273913099896641458499949922475383775878771011361417556799406151773618626138749998464514570482965286184387350245762317271666329142667987131139265167425606863654107927682419958167046956962340419295394058625063862272314570914511355913547470055072878835349142049813368019960713974852351833144227544851625677753419141348585495260230041111323576432417502998832485027071744397105338790364666312325483218209150368759120749671419554589928540715813531144241705501211397506662448276056294585639532800634727428900861538486753011006379264618338782036690340859441153926551954112364946638768223012718907190897165613382555036872673785444132692292217184974818914501886689736449912131900762592363447945036085692999163815947845753538999001633767986447907729462453017601有4888位,用时35.62598秒(改成4000位当1位了,仍然不快,加减法无法提高速度)
2021-04-01 03:57
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
再传一下这个代码:

Private Sub Command1_Click()
Dim a, B
Dim ja(), jb()
a = Trim(Text1): B = Trim(Text2): a3 = a: b3 = B
ts = Timer
If Len(a) < Len(B) Then
a = String(Len(B) - Len(a), "0") & a
B = B
Else
a = a
B = String(Len(a) - Len(B), "0") & B
End If
x = Len(a) \ 4000: Y = x + 2
sb = Y * 2
a = String(Val(sb * 4000 - Len(a)), "0") & a
B = String(Val(sb * 4000 - Len(B)), "0") & B
x = sb / 2
ReDim ja(1 To x): ReDim jb(1 To x)
For I = 1 To x
ja(I) = Mid(a, 8000 * I - 7999, 8000)
jb(I) = Mid(B, 8000 * I - 7999, 8000)
Next
For i1 = 1 To x
a1 = Mid(ja(i1), 1, 4000): a2 = Mid(ja(i1), 4001, 4000)
For i2 = 1 To x
B1 = Mid(jb(i2), 1, 4000): b2 = Mid(jb(i2), 4001, 4000)
C1 = MbC(Trim(a1), Trim(B1)): C2 = MbC(Trim(a2), Trim(b2))
c3 = MPC1(Trim(a1), Trim(a2)): c4 = MPC1(Trim(B1), Trim(b2))
c5 = MbC(Trim(c3), Trim(c4))
D1 = MPC(Trim(c5), Trim(C1)): D1 = MPC(Trim(D1), Trim(C2))
D2 = MPC1(Trim(C1) & String(8000, "0"), Trim(D1) & String(4000, "0"))
D2 = MPC1(Trim(D2), Trim(C2))
d3 = MPC1(Trim(d3) & String(8000, "0"), Trim(D2))
Next
d4 = MPC1(Trim(d4) & String(8000, "0"), Trim(d3))
Next
d4 = qqdl(Mid(d4, Len(d4) - Len(a3) - Len(b3) + 1))
Text3 = d4 & "有" & Len(d4) & "位,用时" & Timer - ts & "秒"
End Sub

Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""

End Sub

Public Function MbC(D1 As String, D2 As String) As String
Dim x, Y ';两数长度
x = Len(D1) \ 4: Y = Len(D2) \ 4
d3 = String(4 * x + 4 - Len(D1), "0") & D1
d4 = String(4 * Y + 4 - Len(D2), "0") & D2
x = x + 1: Y = Y + 1
Dim a() As String
ReDim a(4 To 4 * x + 4 * Y, 4 To 4 * Y)
Dim I, J, C1, C2, CJ, jw, s, t
For J = 4 * Y To 4 Step -4 ';D2
jw = 0 ';进位清0
C2 = Mid(d4, J - 3, 4) ';每位数
For I = 4 * x To 4 Step -4 ';D1
C1 = Mid(d3, I - 3, 4) ';每位数
CJ = Val(C1) * Val(C2) + jw ';计算乘积
c = I + J: r = 4 * Y + 4 - J
a(c, r) = String(4 - Len(CJ Mod 10000), "0") & CJ Mod 10000 ';本位
jw = CJ \ 10000 ';进位
Next
a(c - 4, r) = jw
Next
Dim B() As String
ReDim B(1 To x + Y)
jw = 0
For s = x + Y To 1 Step -1
Bit = jw
For t = 1 To Y
Bit = Bit + Val(a(4 * s, 4 * t))
Next
B(s) = String(4 - Len(Bit Mod 10000), "0") & Bit Mod 10000
jw = Bit \ 10000
Next
If B(1) > 0 Then
MbC = Val(Left(MbC, 5)) & Mid(MbC, 6) & B(1)
Else
MbC = Val(Left(MbC, 5)) & Mid(MbC, 6)
End If
For s = 2 To x + Y
MbC = Val(Left(MbC, 5)) & Mid(MbC, 6) & B(s)
Next
End Function

'该程序已经做了修改,是模仿手工计算的程序,采用4位一组,在位数少于5000的时候,此程序居然比快速傅里叶变换的乘法还快!

Public Function MPC1(D1 As String, D2 As String) As String 'jiafa
  Dim x, Y, jw '两数长度

If Len(D1) >= Len(D2) Then
  d4 = String(Len(D1) - Len(D2), "0") & D2
  d3 = D1
  Else
  d4 = D2
  d3 = String(Len(D2) - Len(D1), "0") & D1
  End If
  x = Len(d3) \ 8: Y = Len(d4) \ 8
  If 8 * x < Len(d3) Then
  d3 = String(8 * x + 8 - Len(d3), "0") & d3
  d4 = String(8 * Y + 8 - Len(d4), "0") & d4
  x = x + 1: Y = Y + 1
  Else
  x = x: Y = Y
  d3 = d3: d4 = d4
  End If
  Dim a() As String, B1() As String, C1() As String, E1() As String
  ReDim a(1 To x)
  ReDim B1(1 To Y)
  ReDim C1(1 To x)
  ReDim E1(1 To x)
  Dim I, J, C2, CJ
  For J = Y To 1 Step -1 'D2
  jw = 0 '进位清0
  B1(J) = Mid$(d4, J * 8 - 7, 8) '每位数
For I = x To 1 Step -1  'D1
     a(I) = Mid$(d3, I * 8 - 7, 8) '每位数
   C1(I) = Val(a(I)) + Val(B1(I)) + Val(jw) '计算jia
   If Len(C1(I)) < 8 Then
   C1(I) = String(8 - Len(C1(I)), "0") & C1(I)
   Else
   C1(I) = C1(I)
   End If
     jw = Left(C1(I), Len(C1(I)) - 8)
     E1(I) = Right(C1(I), 8)
    Next
    Next
    For r = 1 To x
    If jw = 0 Then
    MPC1 = MPC1 & E1(r)
    Else
    jc = jc & E1(r)
    MPC1 = jw & jc
    End If
    Next
   MPC1 = qqdl(Trim(MPC1))
  End Function
  
  Public Function MPC(D1 As String, D2 As String) As String ';jianfaqi
  Dim x, Y ';两数长度
If Len(D1) >= Len(D2) Then
  d4 = String(Len(D1) - Len(D2), "0") & D2
  d3 = D1
  Else
  d4 = D2
  d3 = String(Len(D2) - Len(D1), "0") & D1
  End If
  x = Len(d3) \ 8: Y = Len(d4) \ 8
  d3 = String(8 * x + 8 - Len(d3), "0") & d3
  d4 = String(8 * Y + 8 - Len(d4), "0") & d4
  x = x + 1: Y = Y + 1
  
  Dim a() As String, B1() As String, C1() As String, E1() As String
  ReDim a(1 To x)
  ReDim B1(1 To Y)
  ReDim C1(1 To x)
  ReDim E1(1 To x)
  Dim I, J, C2, CJ, jw
  For J = Y To 1 Step -1 ';D2
  jw = 1 ';yu jie weichuzhi
  B1(J) = Mid(d4, J * 8 - 7, 8) ';每位数
For I = x To 1 Step -1  ';D1
     a(I) = Mid(d3, I * 8 - 7, 8) ';每位数
   C1(I) = Val(1 & a(I)) - Val(B1(I)) - Val(1) + Val(jw) ';计算jia
     jw = Left(C1(I), Len(C1(I)) - 8)
     E1(I) = Right(C1(I), 8)
     If Len(E1(I)) < 8 Then
     E1(I) = String(8 - Len(E1(I)), "0") & E1(I)
     Else
     E1(I) = E1(I)
     End If
     
    Next
    Next
    For r = 1 To x
    MPC = MPC & E1(r)
    If Len(MPC) > Len(D1) Then
    MPC = Mid(MPC, Len(MPC) - Len(D1) + 1)
    Else
    MPC = MPC
    End If
    For I = 1 To Len(MPC)
      If Not Mid(MPC, I, 1) = "0" Then
          Exit For
      End If
  Next
  strTmp = Mid(MPC, I)
    If Len(strTmp) = 0 Then
    MPC = "0"
    Else
  MPC = strTmp
  End If
    Next
   
   
  End Function
  
  Private Function qqdl(sa As String) As String

  
  For I = 1 To Len(sa)
    If Not Mid(sa, I, 1) = "0" Then
        Exit For
    End If
Next
strTmp = Mid(sa, I)
  If Len(strTmp) = 0 Then
  qqdl = "0"
  Else
qqdl = strTmp
 End If
End Function
2021-04-01 03:59
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
修改了一下程序,结果不对,速度有所提高,咋回事呢?采用倒序计算,从最低位算起,结果倒序输出,减少加法计算量,结果错误,再考虑考虑吧。代码暂时发一下:

Private Sub Command1_Click()
Dim a, B
Dim ja(), jb()
a = Trim(Text1): B = Trim(Text2): a3 = a: b3 = B
ts = Timer
If Len(a) < Len(B) Then
a = String(Len(B) - Len(a), "0") & a
B = B
Else
a = a
B = String(Len(a) - Len(B), "0") & B
End If
x = Len(a) \ 300: Y = x + 2: x11 = x
sb = Y * 2
a = String(Val(sb * 300 - Len(a)), "0") & a
B = String(Val(sb * 300 - Len(B)), "0") & B
x = sb / 2
ReDim ja(1 To x): ReDim jb(1 To x)
For I = 1 To x
ja(I) = Mid(a, Len(a) - 600 * I + 1, 600)
jb(I) = Mid(B, Len(B) - 600 * I + 1, 600)
'倒序输出,减少加法计算量,提高速度
Next
jw2 = 0: jw3 = 0
For i1 = 1 To x
a1 = Mid(ja(i1), 1, 300): a2 = Mid(ja(i1), 301, 300)
d3 = ""
For i2 = 1 To x
B1 = Mid(jb(i2), 1, 300): b2 = Mid(jb(i2), 301, 300)
C1 = MbC(Trim(a1), Trim(B1)): C2 = MbC(Trim(a2), Trim(b2))
c3 = MPC1(Trim(a1), Trim(a2)): c4 = MPC1(Trim(B1), Trim(b2))
c5 = MbC(Trim(c3), Trim(c4))
D1 = MPC(Trim(c5), Trim(C1)): D1 = MPC(Trim(D1), Trim(C2))
D2 = MPC1(Trim(C1) & String(600, "0"), Trim(D1) & String(300, "0"))
D2 = MPC1(Trim(D2), Trim(C2))
If Len(D2) <= 1200 Then
D2 = String(1200 - Len(D2), "0") & D2
jw2 = 0
Else
jw2 = Left(D2, Len(D2) - 1200)
D2 = Right(D2, 1200)
End If
If i1 = x11 - 3 And i2 = x11 - 3 Then
d11 = D2
Else
D2 = D2
End If
d3 = Trim(D2) & Trim(d3)
Next

d5 = d3
Print qqdl(Trim(d5))
x3 = Len(d3) \ 300
If Len(d3) = 300 * x3 Then
d3 = d3
jw3 = 0
Else
jw3 = Left(d3, Len(d3) - 300 * x3)
d3 = Right(d3, 300 * x3)
End If
d4 = Trim(d3) & Trim(d4)
Next

d4 = Trim(d4)
If Len(d4) < 300 Then
d4 = qqdl(Trim(d4))
Else
d4 = qqdl(Mid(d4, Len(d4) - Len(a3) - Len(b3) + 1))
End If
d10 = Mid(d4, 1, 88): d11 = Trim(d11)
Text3 = d4 & "有" & Len(d4) & "位,用时" & Timer - ts & "秒"
End Sub

Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""

End Sub

Public Function MbC(D1 As String, D2 As String) As String
Dim x, Y ';两数长度
x = Len(D1) \ 4: Y = Len(D2) \ 4
d3 = String(4 * x + 4 - Len(D1), "0") & D1
d4 = String(4 * Y + 4 - Len(D2), "0") & D2
x = x + 1: Y = Y + 1
Dim a() As String
ReDim a(4 To 4 * x + 4 * Y, 4 To 4 * Y)
Dim I, J, C1, C2, CJ, JW, s, t
For J = 4 * Y To 4 Step -4 ';D2
JW = 0 ';进位清0
C2 = Mid(d4, J - 3, 4) ';每位数
For I = 4 * x To 4 Step -4 ';D1
C1 = Mid(d3, I - 3, 4) ';每位数
CJ = Val(C1) * Val(C2) + JW ';计算乘积
c = I + J: r = 4 * Y + 4 - J
a(c, r) = String(4 - Len(CJ Mod 10000), "0") & CJ Mod 10000 ';本位
JW = CJ \ 10000 ';进位
Next
a(c - 4, r) = JW
Next
Dim B() As String
ReDim B(1 To x + Y)
JW = 0
For s = x + Y To 1 Step -1
Bit = JW
For t = 1 To Y
Bit = Bit + Val(a(4 * s, 4 * t))
Next
B(s) = String(4 - Len(Bit Mod 10000), "0") & Bit Mod 10000
JW = Bit \ 10000
Next
If B(1) > 0 Then
MbC = Val(Left(MbC, 5)) & Mid(MbC, 6) & B(1)
Else
MbC = Val(Left(MbC, 5)) & Mid(MbC, 6)
End If
For s = 2 To x + Y
MbC = Val(Left(MbC, 5)) & Mid(MbC, 6) & B(s)
Next
End Function

'该程序已经做了修改,是模仿手工计算的程序,采用4位一组,在位数少于5000的时候,此程序居然比快速傅里叶变换的乘法还快!

Public Function MPC1(D1 As String, D2 As String) As String 'jiafa
  Dim x, Y, JW '两数长度

If Len(D1) >= Len(D2) Then
  d4 = String(Len(D1) - Len(D2), "0") & D2
  d3 = D1
  Else
  d4 = D2
  d3 = String(Len(D2) - Len(D1), "0") & D1
  End If
  x = Len(d3) \ 8: Y = Len(d4) \ 8
  If 8 * x < Len(d3) Then
  d3 = String(8 * x + 8 - Len(d3), "0") & d3
  d4 = String(8 * Y + 8 - Len(d4), "0") & d4
  x = x + 1: Y = Y + 1
  Else
  x = x: Y = Y
  d3 = d3: d4 = d4
  End If
  Dim a() As String, B1() As String, C1() As String, E1() As String
  ReDim a(1 To x)
  ReDim B1(1 To Y)
  ReDim C1(1 To x)
  ReDim E1(1 To x)
  Dim I, J, C2, CJ
  For J = Y To 1 Step -1 'D2
  JW = 0 '进位清0
  B1(J) = Mid$(d4, J * 8 - 7, 8) '每位数
For I = x To 1 Step -1  'D1
     a(I) = Mid$(d3, I * 8 - 7, 8) '每位数
   C1(I) = Val(a(I)) + Val(B1(I)) + Val(JW) '计算jia
   If Len(C1(I)) < 8 Then
   C1(I) = String(8 - Len(C1(I)), "0") & C1(I)
   Else
   C1(I) = C1(I)
   End If
     JW = Left(C1(I), Len(C1(I)) - 8)
     E1(I) = Right(C1(I), 8)
    Next
    Next
    For r = 1 To x
    If JW = 0 Then
    MPC1 = MPC1 & E1(r)
    Else
    jc = jc & E1(r)
    MPC1 = JW & jc
    End If
    Next
   MPC1 = qqdl(Trim(MPC1))
  End Function
  
  Public Function MPC(D1 As String, D2 As String) As String ';jianfaqi
Dim x, Y ';两数长度
If Len(D1) >= Len(D2) Then
d4 = String(Len(D1) - Len(D2), "0") & D2
d3 = D1
Else
d4 = D2
d3 = String(Len(D2) - Len(D1), "0") & D1
End If
x = Len(d3): Y = Len(d4)
Dim a() As Integer, B1() As Integer, C1() As Integer, E1() As Integer
ReDim a(1 To x)
ReDim B1(1 To Y)
ReDim C1(1 To x)
ReDim E1(1 To x)
Dim I, J, C2, CJ, JW
For J = Y To 1 Step -1 ';D2
JW = 1 ';yu jie weichuzhi
B1(J) = Mid(d4, J, 1) ';每位数
For I = x To 1 Step -1  ';D1
   a(I) = Mid(d3, I, 1) ';每位数
   C1(I) = 10 + a(I) - B1(I) - 1 + JW ';计算jia
   JW = C1(I) \ 10
   E1(I) = C1(I) Mod 10
  Next
  Next
  For r = 1 To x
  MPC = MPC & E1(r)
  For I = 1 To Len(MPC)
    If Not Mid(MPC, I, 1) = "0" Then
        Exit For
    End If
Next
strtmp = Mid(MPC, I)
  If Len(strtmp) = 0 Then
  MPC = "0"
  Else
MPC = strtmp
End If
  Next
  
  
End Function

  
  Private Function qqdl(sa As String) As String

  
  For I = 1 To Len(sa)
    If Not Mid(sa, I, 1) = "0" Then
        Exit For
    End If
Next
strtmp = Mid(sa, I)
  If Len(strtmp) = 0 Then
  qqdl = "0"
  Else
qqdl = strtmp
 End If
End Function



2021-04-01 13:53
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
51750801837147361345408953922231823615475578427966187002956389087112242842559611794590895524485015222232340190036677951157401229518412775512617768569186939216558814320044037671525512763073762127357272238470370174050144130962253437215369727381909754581075278888137687950749577751967083233227932391898438489520107788418593104216764745143648165875043861634459264809523254076330115365651752264033578829280651927862062277153553168278640509846511729608378923480331705134467105387853440058108864733429085916392927954109944314725590758950098556991513109760871599045355054258610189920009222629391227784118536578933067532162200768112408111142115021110731900107445187734955403922470144187293970602024056652942406064101184615113779243566842311336047149767396006622923831778833173731302325162741660053390002572456069410383734906953419854919650114722834689335022576764661864630532595250136417800041415827379233503655173380741283758557001102498493237113089198106283487003030225058520047964863929279622015825870972146222540614667928697270131499340362072956956518213266361286372027834000838185920579641835952404678850816456467012890793914108776148483471455515695596694573035435841962871983614397882366460940068418989292218104650923374259244879331938925143014431488635252724366437874702141802712286424754174951797598162531093933772708024046029028652425912112434874797404878317364682580259997737809632860143160557722236459697738869857870982308547756781808568834445404196611833859447257611721058384661943492980180884154939581533269700568975940675513953240040220315659784214936947443784598154082110443748171557676558299300252057475022409541083454882202785077569281268346332901357829843950754331120530978456454396022570647840977328115888711408099894489014427119253061839770890965114853246067272044090282103668762164047374624856119676063310166566519499552342907590495696658359542582469176737197423550084705962160477441546453931948920780829433665262356431973422034925001341330921812806939990688094288773216182971976433480031438271163051341645350474631300965486818841553843112688792803367397276204832936049162335586140151875524537720425345701193713093955432559579831822084761702059241698184717469616732582600658006352069963017377661059372648121969448644394344799369193952197519795756182552461838014896498816263546256621347748100920475049252091842372001283217811864786225692344297842649982716736752004086642881662614773154743879410328420184057019873899911520017723788801*
51750801837147361345408953922231823615475578427966187002956389087112242842559611794590895524485015222232340190036677951157401229518412775512617768569186939216558814320044037671525512763073762127357272238470370174050144130962253437215369727381909754581075278888137687950749577751967083233227932391898438489520107788418593104216764745143648165875043861634459264809523254076330115365651752264033578829280651927862062277153553168278640509846511729608378923480331705134467105387853440058108864733429085916392927954109944314725590758950098556991513109760871599045355054258610189920009222629391227784118536578933067532162200768112408111142115021110731900107445187734955403922470144187293970602024056652942406064101184615113779243566842311336047149767396006622923831778833173731302325162741660053390002572456069410383734906953419854919650114722834689335022576764661864630532595250136417800041415827379233503655173380741283758557001102498493237113089198106283487003030225058520047964863929279622015825870972146222540614667928697270131499340362072956956518213266361286372027834000838185920579641835952404678850816456467012890793914108776148483471455515695596694573035435841962871983614397882366460940068418989292218104650923374259244879331938925143014431488635252724366437874702141802712286424754174951797598162531093933772708024046029028652425912112434874797404878317364682580259997737809632860143160557722236459697738869857870982308547756781808568834445404196611833859447257611721058384661943492980180884154939581533269700568975940675513953240040220315659784214936947443784598154082110443748171557676558299300252057475022409541083454882202785077569281268346332901357829843950754331120530978456454396022570647840977328115888711408099894489014427119253061839770890965114853246067272044090282103668762164047374624856119676063310166566519499552342907590495696658359542582469176737197423550084705962160477441546453931948920780829433665262356431973422034925001341330921812806939990688094288773216182971976433480031438271163051341645350474631300965486818841553843112688792803367397276204832936049162335586140151875524537720425345701193713093955432559579831822084761702059241698184717469616732582600658006352069963017377661059372648121969448644394344799369193952197519795756182552461838014896498816263546256621347748100920475049252091842372001283217811864786225692344297842649982716736752004086642881662614773154743879410328420184057019873899911520017723788801=
7556716882998132164542923842383303327571414587744407945231984628094341180333379645401978298146221777173676638210455520662548991027738258079052809207506367979455512187396178750941853217122840036369548173301141443509525659039575396074833577505735698624489890609009484046476630120285405249920677430746384775952979253571006564333418318770668897295763186676316027596610915791979399362052348545873602726189815157628544498437263477094638977630956320503964273533163977525985300400140163764751336058941588606383095425479304250618575529978192758289990300748777313373507087899169534601600726668909378749370126592359838422617766896228042969975075390204500676572484489708824182046057468895349664773602280104891398380585108251416838593445588941497288478115303823386739577331255231423489957244275591568150461037869725445901546418956914889103837813221378320099880499014018222342116990922975807022360614693772423577680136784695028608731923425362635577892637791161250909792812244592027954144280337652624474895208455219004636193986840747157071695813497353670133362894692860323066270598965217728993062872216962446859880149083503941970770444499514146251481615455355891089694348978517655365203627102239414675972397411451496039654864285237122341394133341081319157681184871278297244162009155204051736252678723531627067376176552401092960678077093159192363721258615551086210244028150778946872428246586904736306135179599862958086659044075873230749180704294097375208200360588668638762246675631994659687469264929730771195942487110722403264491569659580339622212648438009286938036186964260327035986547258357045971407206610058200602976347523999383865181922739913024160534793296729891903147967615939538080017989865056268513503069595234040512868573781901442113016368782879512898505748504409183579871173283353578093561450614128549476113465293704574415350199809211251250302353728078527764868128594701985044655314403219110999833917069459224211041334269362605375995113469525420239566537833097937858386327131046645751788113574013930471792529884065635032884075622869329557621808335521895799476119004142044890500541438620090562777447751130000909261329303878396436455106869987309301666718583989398588040402824951444064856675445842263297685966918041263021893298981796604977071059320967846872380391890840919482170105740880401218296541029907937510519347050358705983480813581986492137042460853498573079916707484770081554855956869530684391567774298463658614816137084323917799849093176582814231633225913372428423612466210856495539187231340411833577632323874451185173706484461285089824749677761305438557387683736749633373462194191976775633764516401358928444089599637462979827649992076227372487021749898755569840643790040608316199074303780130204856698178197753571118083980228264469315246660706720321473549253687080910220500501487604994891438966605534074832231326018970387146996246570463737202606433086961182778844849001549151459537558697657445108792738772557165652345485482618951057319215263186205069899491924395284187132629600286000461015789270135996723652353173805143533305688124977594025230010770089882211898560785574644193383402929807623847693301624433456643569266279784410750311506231805805162412745226642380700372028842246164443649938025561476022865955883606947259158963779126688676889986175227428603703436567638116170043133849291936656904690623124283553087355492033948676552212967127736905505501855837712416837063149720194692245694320135817871886252902554454999030182089183010482460926026947690168320889188735485209971506524057721238700105747521796982564573171184393270521454579264762513733594509697409616756391302852341220656363105077828326475235942495227272462808215747275147924649643843669902443310109365830832741264193175046495485332869920562106492063369720623830846789716831589263346369224538073293014363288540339129863333926625283484042402138365851904313643815634983424873137867698692157231695545218027817983305816414387440463785100729677866814682691502351373917177037485820190796485619422963345167807142587511496461577026086457435543969343350708810722000686828427652591570514157108840527819136387359452422840879204367016189819409995596874905405091387638297607076213318622769748885632707622063680716409692778071196329698635207401142753201301733635684205072848083075932669436885099662905957430651447597481002504602752915074435606863654107927682419958167046956962340419295394058625063862272314570914511355913547470055072878835349142049813368019960713974852351833144227544851625677753419141348585495260230041111323576432417502998832485027071744397105338790364666312325483218209150368759120749671419554589928540715813531144241705501211397506662448276056294585639532800634727428900861538486753011006379264618338782036690340859441153926551954112364946638768223012718907190897165613382555036872673785444132692292217184974818914501886689736449912131900762592363447945036085692999163815947845753538999001633767986447907729462453017601有4888位,用时8.902344秒(改进版分治法程序结果,总位数对了,最高位数字明显不对,不知道咋错了,再说吧)
2021-04-01 13:59
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
速度快的不可靠,算法有错误,超过8000位的乘法,还是用快速傅里叶变换的乘法吧。
2021-04-01 14:02
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
没法改进了,可能仅仅末尾600位是对的,其他都不对了,不知道咋改呢。还是用快速傅里叶变换吧,或者用快速数论变换的乘法。(分治法可能还有提升的空间,可能还能改进,改天再考虑吧)

[此贴子已经被作者于2021-4-1 18:54编辑过]

2021-04-01 17:42
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
收藏
得分:0 
改进了一下,小数值是对的:123456*456789=56393342784有11位,用时0.3046875秒.
2021-04-01 20:27
快速回复:各位老师好!求助编辑一个大整数的快速乘除法可调用程序
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034976 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved