Private Sub Form_Load() Me.Hide Open App.Path & "\out.txt" For Output As #1 Dim a$, b$ a = "1" b = "1" For i = 1 To 64 a = Bmult(a, "2") b = Bplus(a, b) Next Do While Left(b, 1) = 0 b = Right(b, Len(b) - 1) Loop Print #1, b Close
End End Sub
Function Bmult(A1 As String, A2 As String) Dim NS1, NS2, L1 As Integer, L2 As Integer, Ans1 As String, Ans2 As String
For i = Len(A2) To 1 Step -1 NS2 = Val(Mid(A2, i, 1)) L1 = 0: L2 = 0 For j = Len(A1) To 1 Step -1
Next Ans1 = L1 & Ans1 For k = Len(A2) - i To 1 Step -1 Ans1 = Ans1 & "0" Next If Left(Ans1, 1) = "0" Then Ans1 = Right(Ans1, Len(Ans1) - 1) Ans2 = Bplus(Ans1, Ans2) Ans1 = "" Next
Bmult = Ans2
End Function
Function Bplus(N1 As String, N2 As String) Dim NS1 As Integer, NS2 As Integer, TMP As Integer, Plus As String, FAns As String
Do Until Len(N1) = Len(N2) If Len(N1) > Len(N2) Then N2 = "0" & N2 Else N1 = "0" & N1 End If Loop
For i = Len(N1) To 0 Step -1
If i = 0 Then FAns = TMP & FAns Else NS1 = Mid(N1, i, 1) NS2 = Mid(N2, i, 1) Plus = NS1 + NS2 FAns = ((Plus + TMP) Mod 10) & FAns TMP = (Plus + TMP) \ 10 End If Next If Left(FAns, 1) = "0" Then FAns = Right(FAns, Len(FAns) - 1) Bplus = FAns End Function
Private Sub Form_Load() Me.Hide Open App.Path & "\out.txt" For Output As #2
ans = "1" total = "1" For i = 1 To 64 ans = Mplus(ans, ans) total = Mplus(total, ans) List1.AddItem ans List2.AddItem total Next i
Print #2, total
Close #2 End End Sub
Function Mplus(A, B)
GO = 0
If Len(A) > Len(B) Then T = A A = B B = T End If
For i = 1 To Len(B) - Len(A) A = "0" & A Next i
For i = Len(A) To 1 Step -1 TA = Val(Mid(A, i, 1)) TB = Val(Mid(B, i, 1)) If TA + TB + GO >= 10 Then ans = ((TA + TB + GO) Mod 10) & ans: GO = 1 Else ans = (TA + TB + GO) & ans: GO = 0 Next i
If GO = 1 Then ans = "1" & ans Mplus = ans End Function
因為不知道n3是3還是4
回覆刪除所以當做4來算
Private Sub Form_Load()
Me.Hide
Open App.Path & "\out.txt" For Output As #1
Dim a$, b$
a = "1"
b = "1"
For i = 1 To 64
a = Bmult(a, "2")
b = Bplus(a, b)
Next
Do While Left(b, 1) = 0
b = Right(b, Len(b) - 1)
Loop
Print #1, b
Close
End
End Sub
Function Bmult(A1 As String, A2 As String)
Dim NS1, NS2, L1 As Integer, L2 As Integer, Ans1 As String, Ans2 As String
For i = Len(A2) To 1 Step -1
NS2 = Val(Mid(A2, i, 1))
L1 = 0: L2 = 0
For j = Len(A1) To 1 Step -1
NS1 = Val(Mid(A1, j, 1))
L2 = NS1 * NS2
Ans1 = ((L1 + L2) Mod 10) & Ans1
L1 = (L2 + L1) \ 10
Next
Ans1 = L1 & Ans1
For k = Len(A2) - i To 1 Step -1
Ans1 = Ans1 & "0"
Next
If Left(Ans1, 1) = "0" Then Ans1 = Right(Ans1, Len(Ans1) - 1)
Ans2 = Bplus(Ans1, Ans2)
Ans1 = ""
Next
Bmult = Ans2
End Function
Function Bplus(N1 As String, N2 As String)
Dim NS1 As Integer, NS2 As Integer, TMP As Integer, Plus As String, FAns As String
Do Until Len(N1) = Len(N2)
If Len(N1) > Len(N2) Then
N2 = "0" & N2
Else
N1 = "0" & N1
End If
Loop
For i = Len(N1) To 0 Step -1
If i = 0 Then
FAns = TMP & FAns
Else
NS1 = Mid(N1, i, 1)
NS2 = Mid(N2, i, 1)
Plus = NS1 + NS2
FAns = ((Plus + TMP) Mod 10) & FAns
TMP = (Plus + TMP) \ 10
End If
Next
If Left(FAns, 1) = "0" Then FAns = Right(FAns, Len(FAns) - 1)
Bplus = FAns
End Function
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\out.txt" For Output As #2
ans = "1"
total = "1"
For i = 1 To 64
ans = Mplus(ans, ans)
total = Mplus(total, ans)
List1.AddItem ans
List2.AddItem total
Next i
Print #2, total
Close #2
End
End Sub
Function Mplus(A, B)
GO = 0
If Len(A) > Len(B) Then
T = A
A = B
B = T
End If
For i = 1 To Len(B) - Len(A)
A = "0" & A
Next i
For i = Len(A) To 1 Step -1
TA = Val(Mid(A, i, 1))
TB = Val(Mid(B, i, 1))
If TA + TB + GO >= 10 Then ans = ((TA + TB + GO) Mod 10) & ans: GO = 1 Else ans = (TA + TB + GO) & ans: GO = 0
Next i
If GO = 1 Then ans = "1" & ans
Mplus = ans
End Function
out.txt
9223372036854775808
答案是錯的吧。可惜了。
回覆刪除36893488147419103231
回覆刪除?