VB大數處理常式—–能算任何大的數的次方

來源:互聯網
上載者:User

Private Sub Command1_Click()
Command1.Caption = "請耐心等待計算結果"
stimer = Timer
Text3.Text = pow(Text1.Text, Text2.Text)
Text4.Text = Timer - stimer & "秒"
If Text6.Text = "" Then
    Text6.Text = InputBox("請輸入您所要除的數字", "一個大數除一個整數的餘數")
End If
Text7.Text = modmax(Text3.Text, Val(Text6.Text))
Text5.Text = Len(Trim(Text3.Text))
Command1.Caption = "計算完成"
End Sub
Function pow(ByVal x As String, ByVal y As String) As String
Dim le1 As Long, le As Long, ch1 As String, ch2 As String, ch3 As String
Dim w As Long, fistshu As Integer, secondshu As Integer, n As Integer, t As Integer, m As Integer
ch1 = x
le1 = Len(x)
ch2 = ""
For i = 2 To Val(y)
    For j = le1 To 1 Step -1
        n = le1 - j
        m = Val(Mid(x, j, 1))
        secondshu = 0
        le2 = Len(ch1)
        While le2
           t = Val(Mid(ch1, le2, 1))
           w = m * t
           If n = 0 Or Len(ch2) - n = 0 Then
              firstshu = w Mod 10 + secondshu
           Else
              firstshu = w Mod 10 + secondshu + Val(Mid(ch2, Len(ch2) - n, 1))
           End If
           secondshu = w / 10
           If firstshu >= 10 Then
              secondshu = secondshu + firstshu / 10
              firstshu = firstshu Mod 10
           End If
           If n = 0 Or Len(ch2) - n = 0 Then
              ch2 = firstshu & Trim(ch2)
           Else: Mid(ch2, Len(ch2) - n, 1) = firstshu
                 n = n + 1
           End If
           le2 = le2 - 1
        Wend
   Next j
   If secondshu <> 0 Then
         ch1 = secondshu & ch2
   Else: ch1 = ch2
   End If
   ch2 = ""
Next i
pow = ch1
End Function

'下面是進行求餘數

Function modmax(ByVal x As String, ByVal y As String)
Dim wshu As Integer, le1 As Integer
If y = 0 Then
   Exit Function
End If
wshu = Len(Trim(x))
For i = 1 To wshu
    q = Val(p & Mid(Trim(x), i, 1))
    p = q Mod y
Next i
modmax = p
End Function

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.