| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1344 人关注过本帖
标题:请老师帮忙修改相邻素数差的排序和计数程序
只看楼主 加入收藏
ysr2857
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:34
帖 子:809
专家分:77
注 册:2020-2-10
结帖率:100%
收藏
 问题点数:0 回复次数:0 
请老师帮忙修改相邻素数差的排序和计数程序
把某整数内的相邻素数的差排序,并把不同的差值分别计数。如差为2的=?差为4的=?不用依次写出那么多语句就可以把不同的差值全部计数显示出结果。
如下为我的程序,只发主程序;(谢谢!)
Private Sub Command1_Click()
'研究相邻素数差的个数的程序
Dim a, b
a = Val(Text1)
a1 = a
Q = Val(Text2)
m = Sqr(Q)
If Right(a, 1) Mod 2 = 0 Then
a = a + 1
Else
a = a
End If
s = 0
Do While a <= m
b = a + 2
c = fenjieyinzi0(Val(a))
d = fenjieyinzi0(Val(b))
If InStr(c, "*") = 0 Then
s = s + 1
If s Mod 2 = 0 Then
a3 = a
Else
a = a
End If
If a > 1000 Then
Print a, a3 - a
Else
a = a
End If

Text3 = Text3 & "/" & a
Else
s = s
End If
a = a + 2
Loop
a2 = a
s1 = s
Do While a2 <= Q
B1 = a2 + 2
c1 = fenjieyinzi0(Val(a2))
D1 = fenjieyinzi0(Val(B1))

If InStr(c1, "*") = 0 Then
s1 = s1 + 1
If s1 Mod 2 = 0 Then
a3 = a2
Else
a4 = a2
End If
If a2 > 1800 Then
Print a2, a3 - a2, a2 - a4
Else
a2 = a2
End If
Text3 = Text3 & "/" & a2
Else
s1 = s1
End If
a2 = a2 + 2

Loop
Combo1 = a1 & "与" & Q & "之间有" & s1 & "个素数:" & vbCrLf & Text3
s103 = Text3
s103 = Mid(s103, 1)
Dim i As Integer
Dim ak(), s105, cr(), f
Set f = CreateObject("Scripting.Dictionary")
s105 = Split(s103, "/")
   j1 = UBound(s105)
   Print j1
   For k = 1 To j1
      n1 = n1 + 1
       ReDim Preserve ak(1 To n1)
      ak(n1) = s105(n1)
    Next
    Print ak(1)
     n = 0
           For i = 1 To j1 - 1
             n = n + 1
             ReDim Preserve cr(1 To n)
            m = Val(ak(i + 1)) - Val(ak(i))
            f(m) = ""
            If m = 2 Then
            js = js + 1
            Else
            If m = 4 Then
            js1 = js1 + 1
            Else
            If m = 6 Then
            js2 = js2 + 1
            Else
            m = m
            End If
            End If
            End If
            
      Next
      n = 0
      m = f.Keys
      For i = 0 To f.Count - 1
          ReDim Preserve cr(1 To i + 1)
          cr(i + 1) = m(i)
      Next
     For i = 1 To UBound(cr) - 1
        For j = i + 1 To UBound(cr)
            If cr(i) > cr(j) Then
                temp = cr(j)
                cr(j) = cr(i)
                cr(i) = temp  'c????????????
            End If
        Next j
        
       ' If i Mod 20 = 0 Then
       ' s104 = s104 & temp & "/" & vbCrLf
       ' Else
       ' s104 = s104 & temp & "/"
       ' End If
    Next i
   
      For i = 1 To UBound(cr)
        If i Mod 20 = 0 Then
          s104 = s104 & cr(i) & "/" & vbCrLf
        Else
          s104 = s104 & cr(i) & "/"
        End If
     Next
         Print temp
         MsgBox "ok"
     MsgBox s104  '???????
Text4 = a1 & "~" & Q & "内的素数间隔" & s104 & "差2=" & js & " 差4=" & js1 & " 差6=" & js2
End Sub

Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""
Combo1 = ""
Form1.Cls
End Sub
搜索更多相关主题的帖子: Then 素数 End Next If 
2020-05-02 17:25
快速回复:请老师帮忙修改相邻素数差的排序和计数程序
数据加载中...
 
   



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

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