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