标题:请求优化或者改写成其他语言的快速程序
只看楼主
ysr2857
Rank: 6Rank: 6
等 级:贵宾
威 望:28
帖 子:767
专家分:65
注 册:2020-2-10
结帖率:100%
已结贴  问题点数:20 回复次数:7 
请求优化或者改写成其他语言的快速程序
代码如下:
Public Function tuzis(sa As String) As String 'tuzi shulie
Dim A, B, c
A = Val(sa)
B = 1
B1 = 0
b2 = 1
b3 = 0
Do While B <= A
B1 = b2

s1 = s1 & "/" & Trim(b3)

b2 = b3
b3 = MPC1(Trim(B1), Trim(b2))


B = Val(B + 1)

Loop
tuzis = s1

End Function

Private Sub Command1_Click()
Dim A, B, ak()
A = Val(Text1)
B = tuzis(Val(A))
B1 = ksm2(Val(664))
s105 = Split(B, "/")
   j1 = UBound(s105)
    For k = 1 To j1
      n1 = n1 + 1
       ReDim Preserve ak(1 To n1)
      ak(n1) = s105(n1)
    Next
  For I = 18 To j1 - 3
  A = ak(I)
   B = ak(I + 1)
   c = ak(I + 2)
x = MPC1(MPC1(MbC(Trim(A), Trim(B)), Trim(c)), Trim(B1))
  Y = MPC1(MPC1(MbC(Trim(c), Trim(B)), Trim(A)), Trim(B1))
   z = MPC1(MPC1(MbC(Trim(A), Trim(c)), Trim(B)), Trim(B1))
   X1 = MPC1(Trim(x), 2)
  Y1 = MPC1(Trim(Y), 2)
  z1 = MPC1(Trim(z), 2)
   Do While Val(js) <= 10
   js = Val(js + 1)
   If zhengchuqyushu(MCC(Trim(x), 3)) > 1 Or zhengchuqyushu(MCC(Trim(Y), 3)) > 1 Or zhengchuqyushu(MCC(Trim(z), 3)) > 1 Then
  If nStr(fenjieyinzi0(Trim(x)), "*") = 0 And InStr(fenjieyinzi0(Trim(X1)), "*") = 0 Then
  s = s + 1
  s1 = s1 & "/" & s & " /" & x & "/" & X1 & vbCrLf
  ElseIf InStr(fenjieyinzi0(Trim(Y)), "*") = 0 And InStr(fenjieyinzi0(Trim(Y1)), "*") = 0 Then
  s = s + 1
  s1 = s1 & "/" & s & " /" & Y & "/" & Y1 & vbCrLf
  ElseIf InStr(fenjieyinzi0(Trim(z)), "*") = 0 And InStr(fenjieyinzi0(Trim(z1)), "*") = 0 Then
  s = s + 1
  s1 = s1 & "/" & s & " /" & z & "/" & z1 & vbCrLf
  Else
  s = s
  End If
  End If
  x = MPC1(Trim(x), 2)
  Y = MPC1(Trim(Y), 2)
  z = MPC1(Trim(z), 2)
  X1 = MPC1(Trim(x), 2)
  Y1 = MPC1(Trim(Y), 2)
  z1 = MPC1(Trim(z), 2)
Loop
  Next
  
If s > 0 Then
Text2 = s1
Else
Text2 = "wu  jie"
End If
End Sub

Private Sub Command2_Click()
Text1 = ""
Text2 = ""

End Sub

Private Function ksm2(sa As String) As String '2的快速幂程序
Dim A, B
A = Val(2): B = sa
If B = 1 Then
ksm2 = A
ElseIf B = 0 Then
ksm2 = 1
Else
a1 = A
Do While B > 1
s = Int(Log(B) / Log(2))
s1 = 0
Do While s1 < s
A = MbC(Trim(A), Trim(A))
s1 = s1 + 1
Loop
a2 = A
B = B - 2 ^ s
A = a1
If s2 > 0 Then
a3 = MbC(Trim(a3), Trim(a2))
Else
a3 = a2
End If
s2 = s2 + 1
Loop
If B = 1 Then
ksm2 = MbC(Trim(a3), Trim(a1))
Else
ksm2 = a3
End If
s3 = Len(ksm2)
ksm2 = ksm2
End If


End Function
搜索更多相关主题的帖子: If InStr Trim End Then 
2023-03-02 18:48
ysr2857
Rank: 6Rank: 6
等 级:贵宾
威 望:28
帖 子:767
专家分:65
注 册:2020-2-10
得分:0 
原理:一个小素数(或者合数)加上一个大偶数(这里采用2^n的偶数)就可以得到巨大的素数或者孪生素数,举例如下:
/1 /73786976357262128867/73786976357262128869(这就是此法得到的一对孪生素数,前面的1是序号,/号算是间隔号)
 
/1/1152921504606885899/1152921504606885901
/2/1152921504606888257/1152921504606888259
/3/1152921504606895097/1152921504606895099(这3对孪生素数也是此法得到的)

/1 /76545051729020975577310162521900618820659871603466655644272117978380005723696097587725184512638784526308634214455061267843403507870735540391292521535824647434568377082591826884769598224146796862139607
这个大素数也是此法找到的,兔子数列某3项由蔡氏法构成的数45771991(该数是合数就是45771991=4729*9679不是素数,而是个合数,前面的1是序号)加上个大偶数形成的大素数,大约200位

小数据里面此法得到的素数和孪生素数的概率很高,大数据里面由于程序速度慢搜索范围不能太宽,所以,搜索范围窄的原因还没哟谱找出来大孪生素数,所以,要改进程序,提高速度。

欢迎沟通探讨,共同进步,谢谢您的指导!

这样的数据在其附近的素数和孪生素数是很多的,比如 :

45771991~45772091之间的素数有8个:(用时1.757813E-02秒)
45772003  45772009  45772033  45772037  45772039  45772057  45772061  45772087  
其中有一对孪生素数就是45772037  45772039
2023-03-02 19:04
mrexcel
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:125
专家分:480
注 册:2022-11-3
得分:5 
Select[Range[45771991, 45772091, 2], PrimeQ[#] && PrimeQ[# + 2] &]
2023-03-02 22:21
mrexcel
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:125
专家分:480
注 册:2022-11-3
得分:5 
Select[Range[45771991, 45772091, 2], PrimeQ[#] &]


{45772003, 45772009, 45772033, 45772037, 45772039, 45772057, 45772061, 45772087}
2023-03-02 22:22
mrexcel
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:125
专家分:480
注 册:2022-11-3
得分:5 
Select[2^300 + Range[1, 99999, 2], PrimeQ[#] && PrimeQ[# + 2] &]


{2037035976334486086268445688409378161051468393665936250636140449354381299763336706183404997,2037035976334486086268445688409378161051468393665936250636140449354381299763336706183418029,2037035976334486086268445688409378161051468393665936250636140449354381299763336706183449367,2037035976334486086268445688409378161051468393665936250636140449354381299763336706183457221,2037035976334486086268445688409378161051468393665936250636140449354381299763336706183472479}
2023-03-02 22:25
mrexcel
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:125
专家分:480
注 册:2022-11-3
得分:0 
楼主研究大素数建议学习MATHEMATICA,5楼的结果秒出
2023-03-02 22:27
mrexcel
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:22
帖 子:125
专家分:480
注 册:2022-11-3
得分:5 
Select[Range[1, 99999, 2], 

 PrimeQ[2^800 + #] && PrimeQ[2^800 + # + 2] &]


返回 {25051}
2^800 +25051 与 2^800 +25053是一对孪生素数
2023-03-02 22:30
ysr2857
Rank: 6Rank: 6
等 级:贵宾
威 望:28
帖 子:767
专家分:65
注 册:2020-2-10
得分:0 
/1 /24917830127/24917830129
/2 /63497664521/63497664523
/3 /24917830277/24917830279

谢谢您!好的,精彩!给你点赞!
2023-03-03 00:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-511428-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.053984 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved