数学中国

 找回密码
 注册
搜索
热搜: 活动 交友 discuz
楼主: ysr

数论问题巅峰对决

[复制链接]
发表于 2020-9-25 23:27 | 显示全部楼层
前10行与后10行是一样的,只是位置交换了,

前10行是:A, B, C, D,

后10行是:C, D, A, B,
回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-9-25 23:30 | 显示全部楼层
额,那就是是重复了,就是仅33对吧?
回复 支持 反对

使用道具 举报

发表于 2020-9-25 23:31 | 显示全部楼层
前10行与后10行,只是位置交换了,视作同一种,

前10行是:A, B, C, D,

后10行是:C, D, A, B,

所以,只需算到 p<=n,就行了。
回复 支持 反对

使用道具 举报

发表于 2020-9-25 23:46 | 显示全部楼层
本帖最后由 蔡家雄 于 2020-9-25 23:50 编辑

我的Mathematica 编程是有的,

s=0;
For[k=1; M=24680 ; p=7, p<=M/2, p++,
If[(PrimeQ[p])&&(PrimeQ[p+30k])&&(PrimeQ[M-p])&&(PrimeQ[M-p-30k]),s=s+1;
Print[s,"------2n = ",M," (k = ", k, " p = ", p, " )"]]]

但,新电脑没安装,我也不会安装此计算软件,以前是请人安装的。

回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-9-25 23:47 | 显示全部楼层
主程序已经发了,在540#楼。下面发一下可调用程序,比较复杂,代码太长,不知道一次是否能发完?
试试吧:
Private Function fenjieyinzi0(n As String) As String
If Len(n) < 10 Then
fenjieyinzi0 = fenjieyinzi(Trim(n))
Else
Dim a
n = Trim(n)
n1 = MPC(Trim(n), 1)
a = 123
'a为明文
a1 = zzxc(Trim(n), Trim(a))
If Val(a1) > 1 Then
fenjieyinzi0 = a1 & "*"
Else
c = 999
'c为公约
Do While zzxc(Trim(n1), Trim(c)) > 1
c = Val(c - 1)
Loop
d = qniyuan(Trim(c), Trim(n1))
'd为逆元为私钥
a2 = qksmimo(Trim(a), Trim(c), Trim(n))
'a2为密文
a3 = qksmimo(Trim(a2), Trim(d), Trim(n))
If MBJC(Trim(a3), Trim(a)) = 0 Then
fenjieyinzi0 = "这是素数有" & Len(n) & "位"
Else
fenjieyinzi0 = "2*2"
End If
End If


End If
End Function



Private Function fenjieyinzi1(a As String) As String
If Len(a) < 6 Then
fenjieyinzi1 = fenjieyinzi(Trim(a))
Else
x = 3
Do While InStr(MCC(Trim(a), 2), "/") = 0 And MBJC(Trim(a), 4) >= 0

  
If b = 0 Then
fenjieyinzi1 = fenjieyinzi1 & "2"
b = 1
Else
fenjieyinzi1 = fenjieyinzi1 & "*2"
End If
a = MCC(Trim(a), 2)
k = a
  
Loop

Do While MBJC(Trim(a), "0001") > 0
Do While MBJC(Trim(x), zhengchuqy(MBBC(Trim(a)))) <= 0
Do While InStr(MCC1(Trim(a), Trim(x)), "/") = 0 And MBJC(Trim(a), MbC(Trim(x), Trim(x))) >= 0
  
If b = 0 Then
fenjieyinzi1 = fenjieyinzi1 & x
b = 1
Else
fenjieyinzi1 = fenjieyinzi1 & "*" & x
End If
a = MCC1(Trim(a), Trim(x))
Loop
  
x = MPC1(Trim(x), 2)
Loop
  
k = a
a = 1
Loop
  
If b = 1 Then
fenjieyinzi1 = fenjieyinzi1 & "*" & k
Else
fenjieyinzi1 = "这是一个质数"
End If

End If
End Function



Private Function fenjieyinzi(sa As String) As String
Dim x, a, b
x = sa
b = Int(Sqr(Val(x)) / 2)
If x = 3 Or x = 2 Then
a = True
Else
If x Mod 2 = 0 Then
a = False
Else

For i = 3 To 2 * b + 1 Step 2
If x Mod i = 0 Then
a = False
Exit For

Else: a = True

End If
Next
End If
End If
If a = True Then
fenjieyinzi = "这是个素数"
Else
fenjieyinzi = "2*2"
End If


End Function
Public Function DeleteSpace1(Tmp As String) As String
  '删掉字符串中的换行符和空格的程序
  Dim a As String, b As String
Dim i As Long, j As Long, k As Long

a = Tmp
b = ""
k = Len(a)
For i = 1 To k
j = Asc(Mid(a, i))
If j <> 10 And j <> 13 And j <> 32 And j <> Asc(" ") Then '最后一个百条件是全角空格
b = b & Chr(j)
End If
Next
DeleteSpace1 = b
End Function

Private Function zzxc(sa As String, sb As String) As String
Dim a, b, c, d, r
  a = Trim(sa)
  b = Trim(sb)
  If Len(a) < 10 And Len(b) < 10 Then
  
  If Val(a) > Val(b) Then
     c = a
     d = b
  Else
     c = b
     d = a
  End If
Do Until Val(c) Mod Val(d) = 0
     r = c Mod d
     c = d
     d = r
  Loop
  
  Else
  
  If MBJC(Trim(a), Trim(b)) >= 1 Then
  c = a
  d = b
  Else
  c = b
  d = a
  End If
  Do Until zhengchuqyushu(MCC1(Trim(c), Trim(d))) = 0
  r = zhengchuqyushu(MCC1(Trim(c), Trim(d)))
  c = d
  d = r
  Loop
  End If

  
  zzxc = d
  
End Function

Private Function qniyuan(sa As String, sb As String) As String
Dim n, p, a, b, c, d, r
  n = Trim(sa)
  p = Trim(sb)
  a = 1
  b = 0
  c = 0
  d = 1
  If Len(n) < 10 And Len(p) < 10 Then
  
  If Val(n) > Val(p) Then
     m = n
     Q = p
     s1 = 1
  Else
     m = p
     Q = n
     s1 = 0
  End If
Do Until Val(m) Mod Val(Q) = 0
    s = m \ Q
     r = m Mod Q
     s1 = s1 + 1
     If s1 Mod 2 = 1 Then
     a = a
     b = a * s + b
     c = c
     d = c * s + d
     Else
     b = b
     a = a + b * s
     d = d
     c = c + d * s
     End If
     m = Q
     Q = r
  Loop
  If Val(a + b * m) = p Then
  b = b
  a = a + b * (m - 1)
  d = d
  c = c + d * (m - 1)
  Else
  If Val(b + a * m) = p Then
  a = a
  b = b + a * m
  c = c
  d = d + c * m
  Else
  b = b
  a = a + b * (m - 1)
  d = d
  c = c + d * (m - 1)
  End If
  End If
x = (a + b) Mod p
  y = (c + d) Mod n
  
  
  Else
  
  If MBJC(Trim(n), Trim(p)) >= 1 Then
  m = n
  Q = p
  s1 = 1
  Else
  m = p
  Q = n
  s1 = 0
  End If
  Do Until zhengchuqyushu(MCC1(Trim(m), Trim(Q))) = 0
  s = zhengchuqy(MCC1(Trim(m), Trim(Q)))
  r = zhengchuqyushu(MCC1(Trim(m), Trim(Q)))
  s1 = s1 + 1
  If s1 Mod 2 = 1 Then
  a = a
  b = MPC1(MbC(Trim(a), Trim(s)), Trim(b))
  c = c
  d = MPC1(MbC(Trim(c), Trim(s)), Trim(d))
  Else
  b = b
  a = MPC1(Trim(a), MbC(Trim(b), Trim(s)))
  d = d
  c = MPC1(Trim(c), MbC(Trim(d), Trim(s)))
  End If
  
  m = Q
  Q = r
  Loop
  
  If MPC1(Trim(a), MbC(Trim(b), Trim(m))) = p Then
  b = b
  a = MPC1(Trim(a), MbC(Trim(b), MPC(Trim(m), 1)))
  d = d
  c = MPC1(Trim(c), MbC(Trim(d), MPC(Trim(m), 1)))
  Else
  If MPC1(Trim(b), MbC(Trim(a), Trim(m))) = p Then
  a = a
  b = MPC1(Trim(b), MbC(Trim(a), Trim(m)))
  c = c
  d = MPC1(Trim(d), MbC(Trim(c), Trim(m)))
  Else
  b = b
  a = MPC1(Trim(a), MbC(Trim(b), MPC(Trim(m), 1)))
  d = d
  c = MPC1(Trim(c), MbC(Trim(d), MPC(Trim(m), 1)))
  End If
  End If
Do While Left(a, 1) = "0"
    a = Mid(a, 2)
Loop
  
  End If
  
  qniyuan = a
End Function

Private Function qksmimo(sa As String, sb As String, sc As String) As String
Dim c, e, n, d
c = Trim(sa)
e = Trim(sb)
n = Trim(sc)
d = 1
If Len(c) < 5 And Len(e) < 5 And Len(n) < 5 Then
c = Val(c): n = Val(n)
Do While e > 0
If Right(e, 1) Mod 2 = 0 Then
c = c * c Mod n
e = e / 2

Else
d = d * c Mod n
e = e - 1
End If
Loop
Else
c = c
Do While MBJC(Trim(e), 1) >= 0
If Right(e, 1) Mod 2 = 0 Then
c = zhengchuqyushu(MCC1(MbC(Trim(c), Trim(c)), Trim(n)))
e = zhengchuqy(MCC1(Trim(e), 2))
Else
d = zhengchuqyushu(MCC1(MbC(Trim(c), Trim(d)), Trim(n)))
e = MPC(Trim(e), 1)
End If
Loop
End If

qksmimo = d
End Function




Private Function zhengchuqyushu(sa As String) As String
If InStr(sa, "/") = 0 Then
zhengchuqyushu = 0
Else
zhengchuqyushu = Mid(sa, InStr(sa, "/") + 1)
End If


End Function


Private Function zhengchuqy(sa As String) As String
If InStr(sa, "/") = 0 Then
zhengchuqy = sa
Else
zhengchuqy = Left(sa, InStr(sa, "/") - 1)
End If


End Function


Public Function MBBC(D1 As String) As String 'kai pingfang
If Len(D1) < 10 Then
jss = Int(Sqr(D1))
JW = Val(D1) - (jss) ^ 2
  If JW = 0 Then
  MBBC = jss
  Else
  MBBC = jss & "/" & JW
    End If
Else
Dim x 'shuju changdu
x = Len(D1) \ 4
D2 = String(4 - Len(D1) + 4 * x, "0") & D1
Dim a() As String
ReDim a(4 To 4 * x + 4)
Dim b() As String
ReDim b(2 To 2 * x)
Dim i, j, js
  For i = 4 To 4 * x + 4 Step 4
  
a(i) = Mid(D2, i - 3, 4)
js = Int(Sqr(Val(a(4) & a(8))))
JW = Val(a(4) & a(8)) - (js) ^ 2
Next
   j = 4
   Do While j <= 2 * x
   
   jws = MPC1(JW & "0000", a(2 * j + 4))
   If MBJC(Trim(jws), MbC(Trim(js), 200)) <= 0 Then
    b(j) = "00"
    Else
    jwc = Left(jws, Len(jws) - Len(MbC(Trim(js), 200)) + 2) \ Left(MbC(Trim(js), 200), 2)
    If Len(jwc) > 2 Then
     b(j) = 99
     Else
     b(j) = jwc
     End If
   
     
     Do While MBJC(Trim(jws), MbC(MPC1(b(j), MbC(Trim(js), 200)), b(j))) = -1
     
     b(j) = b(j) - 1
     
               Loop
          End If
          JW = MPC(Trim(jws), MbC(MPC1(MbC(200, Trim(js)), b(j)), b(j)))
      
     js = MPC1(MbC(Trim(js), 100), Trim(b(j)))
     
      
   j = j + 2
   If JW = 0 Then
      
   MBBC = js
   Else
   MBBC = js & "/" & JW
   End If
   Loop
   
End If
End Function

Public Function MBJC(D1 As String, D2 As String) As String ';bijiao
If Len(D1) <= 10 And Len(D2) <= 10 Then
If Val(D1) > Val(D2) Then
MBJC = 1
Else
If Val(D1) = Val(D2) Then
MBJC = 0
Else
MBJC = -1
End If
End If
Else

If Len(D1) > Len(D2) Then
MBJC = 1
Else
If Len(D1) < Len(D2) Then
MBJC = -1
Else
If Len(D1) = Len(D2) Then
Dim x, y
x = Len(D1) \ 4: y = Len(D2) \ 4
Dim a() As String, b() As String
ReDim a(4 To 4 * x + 4)
ReDim b(4 To 4 * y + 4)
If Val(Left(D1, Len(D1) - 4 * x)) > Val(Left(D2, Len(D2) - 4 * y)) Then
  MBJC = 1
  Else
  If Val(Left(D1, Len(D1) - 4 * x)) < Val(Left(D2, Len(D2) - 4 * y)) Then
  MBJC = -1
  Else
  For i = 4 To 4 * x Step 4
  a(i) = Mid(D1, Len(D1) - i + 1, 4)
  b(i) = Mid(D2, Len(D2) - i + 1, 4)
  Next
  j = 4 * x
  Do While a(j) = b(j) And j >= 8
  
  j = j - 4
     Loop
     
     
   If Val(a(j)) - Val(b(j)) > 0 Then
   MBJC = 1
   Else
   If Val(a(j)) - Val(b(j)) < 0 Then
   MBJC = -1
   Else
   MBJC = 0
   End If
   
  End If
  
  
  
End If
End If
End If
End If
End If
End If
End Function

Public Function MCC(D1 As String, D2 As String) As String ';除数少于8位的除法
If Len(D1) < Len(D2) Then
   MCC = "0" & "/" & D1
   Else
   If Len(D1) < 9 Then
    MCC = Val(D1) \ Val(D2) & "/" & Val(D1) - (Val(D1) \ Val(D2)) * Val(D2)
     If Mid(MCC, InStr(MCC, "/") + 1) = 0 Then
  MCC = Left(MCC, InStr(MCC, "/") - 1)
Else
MCC = MCC
End If
   
    Else
   
   Dim x ';fen duan changdu
   x = Len(D1)
   
     
   
     Dim a() As String
      ReDim a(1 To x)  ';定义数组的储存空间
      For i = 1 To x Step 1  ';把被除数各位放在a()中
       a(i) = Mid(D1, i, 1)
        
      
       Next i
      Dim b() As String
      JW = 0
     ReDim b(1 To x)
     For j = 1 To x Step 1
    b(j) = Val(JW & a(j)) \ Val(D2)
      JW = Val(JW & a(j)) - Val(b(j)) * Val(D2)
       Next j
       For r = 1 To x
       If JW = 0 Then
          MCC = MCC & b(r)
          Else
          CJ = CJ & b(r)
          MCC = CJ & "/" & JW
      
    End If
   
    For i = 1 To Len(MCC)
   If Not Mid(MCC, i, 1) = "0" Then
       Exit For
   End If
Next
strtmp = Mid(MCC, i)
If Len(strtmp) = 0 Then
MCC = "0"
Else
MCC = strtmp
End If
   
   Next
   
   End If
     
     End If
   
End Function

Public Function MCC1(D1 As String, D2 As String) As String ';大整数的除法
Dim ss
ss = MBJC(D1, D2)
If ss = -1 Then
MCC1 = "0" & "/" & D1
  Else
  If ss = 0 Then
   MCC1 = 1
   Else
   If Len(D1) = Len(D2) Then
     s = Val(Left(D1, 1)) \ Val(Left(D2, 1))

Do While MBJC(MbC(Trim(s), Trim(D2)), D1) = 1
  s = s - 1
  Loop
  If MBJC(MbC(Trim(s), Trim(D2)), D1) = 0 Then
   MCC1 = s
   Else
   MCC1 = s & "/" & MPC(Trim(D1), MbC(Trim(s), Trim(D2)))

End If
    Else
    If Len(D2) < 9 Then
     MCC1 = MCC(D1, D2)
     Else
    Dim x, y ';定义分段长度
    x = Len(D1): y = Len(D2)
   
Dim JW, jcc, jss, jcs

  Dim a() As String, b() As String
  
  ReDim a(1 To x)
  ReDim b(1 To y)
  For i = 1 To x
  a(i) = Mid(D1, i, 1)
  Next
  For j = 1 To y
  b(j) = Mid(D2, j, 1)
  Next
  jcc = Val(a(1) & a(2)) \ Val(b(1) & b(2))
   
      
        
  jss = MbC(Trim(jcc), D2)
   For i1 = 1 To y
    jws = jws & a(i1)
      Next
      
      Do While MBJC(Trim(jws), Trim(jss)) = -1
      jcc = jcc - 1
      jss = MbC(Trim(jcc), D2)
      Loop
  JW = MPC(Trim(jws), Trim(jss))
  
    z = x - y
   
    Dim c() As String
    ReDim c(1 To z)
    For s = 1 To z
     If MBJC(JW & a(s + y), D2) = -1 Then
       c(s) = "0"
       Else
     jwc = Val(Left(JW & a(s + y), 3)) \ Val(Left(D2, 2))
      If Len(jwc) > 1 Then
      c(s) = "9"
       Else
        c(s) = jwc
         End If
      
     Do While MBJC(JW & a(s + y), MbC(Val(c(s)), D2)) = -1
    c(s) = Right(10000 + Val(c(s) - 1), 1)
     Loop
     End If
   
     JW = MPC(JW & a(s + y), MbC(Val(c(s)), D2))
     
    jcc = jcc & c(s)
    Next s
    If JW = 0 Then
    MCC1 = jcc
    Else
    MCC1 = jcc & "/" & JW
    End If
   
  For i = 1 To Len(MCC1)
    If Not Mid(MCC1, i, 1) = "0" Then
        Exit For
    End If
Next
strtmp = Mid(MCC1, i)
  If Len(strtmp) = 0 Then
  MCC1 = "0"
  Else
MCC1 = strtmp
End If
   
   
   
    End If
   
   
   
   
   
  
  End If
End If
End If
End Function
Public Function MbC(D1 As String, D2 As String) As String '乘法
Dim x, y '两数长度
x = Len(D1): y = Len(D2)
Dim a() As Integer
ReDim a(1 To x + y, 1 To y)
Dim i, j, c1, C2, CJ, JW
For j = y To 1 Step -1 'D2
JW = 0 '进位清0
C2 = Mid$(D2, j, 1) '每位数
For i = x To 1 Step -1 'D1
  c1 = Mid$(D1, i, 1) '每位数
  CJ = c1 * C2 + JW '计算乘积
  c = i + j: r = y + 1 - j
  a(c, r) = CJ Mod 10 '本位
  JW = CJ \ 10 '进位
Next
a(c - 1, r) = JW
Next
Dim b() As Integer
ReDim b(1 To x + y)
JW = 0
For i = x + y To 1 Step -1
Bit = JW
For j = 1 To y
  Bit = Bit + a(i, j)
Next
b(i) = Bit Mod 10
JW = Bit \ 10
Next
If b(1) > 0 Then
MbC = MbC & b(1)
Else
MbC = MbC
End If
For i = 2 To x + y
MbC = MbC & b(i)
Next
End Function

Public Function MPC(D1 As String, D2 As String) As String ';jianfaqi
Dim x, y ';两数长度
If Len(D1) >= Len(D2) Then
D4 = String(Len(D1) - Len(D2), "0") & D2
D3 = D1
Else
D4 = D2
D3 = String(Len(D2) - Len(D1), "0") & D1
End If
x = Len(D3): y = Len(D4)
Dim a() As Integer, B1() As Integer, c1() As Integer, E1() As Integer
ReDim a(1 To x)
ReDim B1(1 To y)
ReDim c1(1 To x)
ReDim E1(1 To x)
Dim i, j, C2, CJ, JW
For j = y To 1 Step -1 ';D2
JW = 1 ';yu jie weichuzhi
B1(j) = Mid(D4, j, 1) ';每位数
For i = x To 1 Step -1  ';D1
   a(i) = Mid(D3, i, 1) ';每位数
   c1(i) = 10 + a(i) - B1(i) - 1 + JW ';计算jia
   JW = c1(i) \ 10
   E1(i) = c1(i) Mod 10
  Next
  Next
  For r = 1 To x
  MPC = MPC & E1(r)
  For i = 1 To Len(MPC)
    If Not Mid(MPC, i, 1) = "0" Then
        Exit For
    End If
Next
strtmp = Mid(MPC, i)
  If Len(strtmp) = 0 Then
  MPC = "0"
  Else
MPC = strtmp
End If
  Next
  
  
End Function
  Public Function MPC1(D1 As String, D2 As String) As String 'jiafa
Dim x, y '两数长度

If Len(D1) >= Len(D2) Then
D4 = String(Len(D1) - Len(D2), "0") & D2
D3 = D1
Else
D4 = D2
D3 = String(Len(D2) - Len(D1), "0") & D1
End If
x = Len(D3): y = Len(D4)
Dim a() As Integer, B1() As Integer, c1() As Integer, E1() As Integer
ReDim a(1 To x)
ReDim B1(1 To y)
ReDim c1(1 To x)
ReDim E1(1 To x)
Dim i, j, C2, CJ, JW
For j = y To 1 Step -1 'D2
JW = 0 '进位清0
B1(j) = Mid$(D4, j, 1) '每位数
For i = x To 1 Step -1  'D1
   a(i) = Mid$(D3, i, 1) '每位数
   c1(i) = a(i) + B1(i) + JW '计算jia
   JW = c1(i) \ 10
   E1(i) = c1(i) Mod 10
  Next
  Next
  For r = 1 To x
  If JW = 0 Then
  MPC1 = MPC1 & E1(r)
  Else
  jc = jc & E1(r)
  MPC1 = JW & jc
  End If
  Next
  
End Function


回复 支持 反对

使用道具 举报

发表于 2020-9-25 23:52 | 显示全部楼层
我的 Mathematica 编程是有的,

s=0;
For[k=1; M=24680 ; p=7, p<=M/2, p++,
If[(PrimeQ[p])&&(PrimeQ[p+30k])&&(PrimeQ[M-p])&&(PrimeQ[M-p-30k]),s=s+1;
Print[s,"------2n = ",M," (k = ", k, " p = ", p, " )"]]]

但,新电脑没安装,我也不会安装此计算软件,以前是请人安装的。


回复 支持 反对

使用道具 举报

 楼主| 发表于 2020-9-25 23:56 | 显示全部楼层
本帖最后由 ysr 于 2020-9-25 16:04 编辑

发出来了,可以复制到vb开发软件中试试,用vb6.0就行,或者用新版本的excel也能运行,不知道咋弄?
我的excel没有激活,单位的excel是不能运行的,版本旧了,可能是版本旧的缘故。
最好是在vb6.0下运行。控件有text共4个,combo一个(就是个下拉菜单),按钮就是command两个,共7个控件!
回复 支持 反对

使用道具 举报

发表于 2020-9-26 00:00 | 显示全部楼层
我的 Mathematica 编程是有的,M<=10^1000也可验证是否有解,

s=0;
For[k=1; M=24680 ; p=7, p<=M/2, p++,
If[(PrimeQ[p])&&(PrimeQ[p+30k])&&(PrimeQ[M-p])&&(PrimeQ[M-p-30k]),s=s+1;
Print[s,"------2n = ",M," (k = ", k, " p = ", p, " )"]]]

但,新电脑没安装,我也不会安装此计算软件,以前是请人安装的。

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|数学中国 ( 京ICP备05040119号 )

GMT+8, 2025-6-29 13:28 , Processed in 0.095154 second(s), 14 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表