|
我这个你看一下, 有时间我代码再优化一下.
方程不一样,请代入不同的变数 p (第一题2 秒左右, 第二题 6分钟左右)
代码如下.
Dim a(200), b(200), c(200), d(200), e(200), resultstring As String, total, total1
Sub test()
Dim k As Double, m As Double, n As Double, flag, i, p As Long
p = 61 '乘数赋值给P 61 or 73
flag = 0
k = 1
While k > 0
m = k * k * p + 1
n = m ^ 0.5
If Val(n) = Int(n) Then
If n * n = m Then
Call abc(k, p, 1)
Call ab(n)
For i = 0 To total - 5
If c(i) = d(i) Then
flag = 1
Else
i = total
flag = 0
End If
Next
If flag = 1 Then
Debug.Print "最小的正整数解如下"
Debug.Print "X="; n
Debug.Print "Y="; k
k = -3
End If
End If
End If
k = k + 1
Wend
End Sub
Sub ab(n As Double)
Dim i, j, k, t, add
For i = 0 To 200
a(i) = 0
b(i) = 0
c(i) = 0
Next
k = n
t = k
For i = 0 To Len(t) - 1
a(i) = Right(t, 1)
t = Left(t, Len(t) - 1)
Next
For i = 0 To Len(k) - 1
For j = 0 To Len(k) - 1
b(i + j) = a(i) * a(j)
c(i + j) = c(i + j) + b(i + j)
If c(i + j) > 9 Then
add = c(i + j) \ 10 ' add 进位的数
c(i + j) = c(i + j) Mod 10
c(i + j + 1) = c(i + j + 1) + add
Else
add = 0
End If
Next
Next
total = i + j
End Sub
Sub abc(n As Double, m As Long, u As Long)
Dim i, j, k, t, add, f
For i = 0 To 200
a(i) = 0
b(i) = 0
c(i) = 0
d(i) = 0
Next
k = n
t = k
For i = 0 To Len(t) - 1
a(i) = Right(t, 1)
t = Left(t, Len(t) - 1)
Next
For i = 0 To Len(k) - 1
For j = 0 To Len(k) - 1
b(i + j) = a(i) * a(j)
c(i + j) = c(i + j) + b(i + j)
If c(i + j) > 9 Then
add = c(i + j) \ 10 ' add 进位的数
c(i + j) = c(i + j) Mod 10
c(i + j + 1) = c(i + j + 1) + add
Else
add = 0
End If
Next
Next
total = i + j
If m > 0 Then
For i = 0 To 200
a(i) = 0
b(i) = 0
Next
k = m
t = m
For i = 0 To Len(t) - 1
e(i) = Right(t, 1)
t = Left(t, Len(t) - 1)
Next
For i = 0 To total
For j = 0 To Len(k) - 1
b(i + j) = c(i) * e(j)
d(i + j) = d(i + j) + b(i + j)
If d(i + j) > 9 Then
add = d(i + j) \ 10 ' add 进位的数
d(i + j) = d(i + j) Mod 10
d(i + j + 1) = d(i + j + 1) + add
Else
add = 0
End If
Next
Next
total1 = i + j
If u > 0 Then
d(0) = d(0) + u
If d(0) > 9 Then
d(0) = d(0) \ 10
d(1) = d(1) + d(0) Mod 10
End If
End If
End If
End Sub |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?免费注册
x
|