当前位置:早雪网网络学院编程文档VB → 整数幂的求解

整数幂的求解

减小字体 增大字体 作者:未知  来源:从互联网收集整理并转载  发布时间:2005-3-8 0:46:10

求整数的幂:

Private Sub Command1_Click()
power 64, 10000' 64^10000
End Sub

Sub power(ByVal x As Long, ByVal n As Integer, Optional ByRef result As String)
Dim a() As Long, s() As String, i As Long, temp As Long
ReDim a(1 To 1)
a(1) = 1
k = 0
stimer = Timer
Do While k < n
k = k + 1
temp = UBound(a)
For i = 1 To temp
a(i) = a(i) * x
Next

ReDim Preserve a(1 To temp + Len(CStr(x)))

For i = 1 To UBound(a) - 1

temp = a(i) \ 10
a(i) = a(i) Mod 10
a(i + 1) = a(i + 1) + temp
Next

temp = UBound(a)
If a(temp) = 0 Then ReDim Preserve a(1 To temp - 1)
Loop

temp = UBound(a)
ReDim s(1 To temp)
For i = 1 To temp
s(i) = a(temp + 1 - i)
Next

result = Join(s, "")
Debug.Print result
Debug.Print x & "^" & n & " : 用时 "; Timer - stimer & " 秒, 结果 " & temp & " 位"

Erase a()
Erase s()
End Sub

630579487001782335726002615792364094952165878414343610620052345960454000623869717150110134871530406526506596116621245692979780766018454723814941962225280444496680617986892514285389144879868315356003294016268897967389615776485793286944718984742918155008669160686304394046689980772947571955818313574524053261334280151435474048213519731874464008804365682389586791274105235358818815781558634177999971887863992158897446085044123998978046463312787515180116167648729645857420185283426852765196485647629155480382695950964878246182512241779417530644366508296359890621342374743216814827298677837537127191389325078789702161244755212399071022208336288737320260669289128618363837680219125084636139500779965085831721640867438122082462575279544168944143807852182258001494675170105254593973657504895409323103589111263340101457860479633052538616499311242755803364866160690679932450546437333357801314944297615473518989151906689225640218032168511843254194475054735008588057580564616708627171314609458370995184597065870225908848090609713158371
205008197360061232451962937688497529185472891365374205366335638167903354851268543866741594606404778534413170189227201660243619326967118038553371962949277208611272730183912256392169184870667944551006135610198093987592067804976863451816862307886633527590311207052252043768778150433169161733611555938489871782963975066190929234551131559841571219089936524902467554784865684002055438864764444866339943612895772503011311879159691376482427895403915622449283749625756784860338788476681740004728579641442965642959564639766764223515787186952827717731160511307110493718870865880919337618540298533991930633466084027065359489961390152286370116858912107273055560580787851459733197677294187776832842097078060202022027347770889453004485643650680648932007300960564393886467917909904960608783438777615763283775134863267945078612456538772448826813203861043025279711593925705041327141571011507971121651524792216109781980914617019822750999131251863238026170615386840438148569702786906933865851274638343385712046219029162571509363027869055435730
429085517055505659390078597470099763987912665827381967222100517688361911856562045550699068370204358486041799652466496393629809823547446470487340163837893911386650403512201648508514369963595551391277057079056399608836947379823991414202398077695031343888053980166397119815825596216497179187835606569972936688490082772885423435897296247583846518281709817002372094259257011911186860161020695498338152117586282747593184230597682546827932485961426050591031324727399771913073074886381694159602268208287932011921621806836029797523144542603011403542435848724279434874580651513120987385224015560826922143758960084850481616008702812955429370561216593625952988573764377424493879680124881777948955602646146818522247226121416516490230029247021413959149857206863559755840857958622848452696631033480008424661993996267616639944950038417398789125641585062459314158580332645047644732026367338770546419253569114214636696123272197993104943714146812596980001652585063539583682492579141200588415959421399867466637018438917328027676700294241110305
151723647617990933786645898674468083434777517538496306710859051733209813213028856802422861690316062746995446485696302069469102883800161777088691341298861077626783672091828398295559253571213477129229519112459588318460125742636537896065007986359908708043613870250710461752092697496012501214715303983812617322977279082628406313970972026421028742896365316672789683557386787541935952322909104902657948824373092671369190596276568559714506439553558870368349189639960575352312185206024068012116556823403715521110293851453030761251269612239542697576948600722974630905181935662967296748946375309390327981922468835534506155439412287993812194642080538270331586431027508968936273382304667107559610116800783353297931686306926688557845509224379372758090161374585537360616048898145898086624676286838871341987114020269752164314966080289772691338930959173350526444933687408915809819076458318618144960257444943352912923657419250589949298923948662284031593328768670297110994123521818295788090336779026174423964580157532010392822061149863125274
630133015533889706124023013996010456366192093519750674109298100275475717183690454030432924308866307440272102147718104615756175531619541310779

[1] [2] [3] [4]  下一页


Tags:整数,求解
[数据载入中...] [返回上一页] [打 印]