﻿ Math Pro 數學補給站

(1) d = 2*3*5*7 = 210

(2) d = 2*3*5*7*11 = 2310

(3) d = 2*3*5*7*11*13 = 30030

Ans: 若限定首項10萬以內的質數( 2 ≤ a ≤ 100000 ), 公差30030以內,

( 首項 , 公差 ) = ( a, d ) = ( 23143, 30030 ) , ( 53173, 30030 ) ,  ( 75307, 30030 )

Sub my_prime()

Cells.ClearContents
r = 1

For n = 2 To 100000
If is_prime(n) Then
Cells(r, 1) = n
r = r + 1
End If
Next

r = 1
U = [A65536].End(xlUp).Row
M = 5
d = 2 * 3 * 5 * 7 * 11 * 13

For n = 1 To U
a = Cells(n, 1)
S = 0

For i = 1 To M
If is_prime(a + i * d) Then
S = S + 1
End If
Next

If S = M Then
Cells(r, 2) = a
r = r + 1
End If
Next

r = 1
U = [B65536].End(xlUp).Row
M = 10

For n = 1 To U
a = Cells(n, 2)
S = 0

For i = 1 To M
If is_prime(a + i * d) Then
S = S + 1
End If
Next

If S = M Then
Cells(r, 3) = a
r = r + 1
End If
Next

End Sub

Function is_prime(n) As Boolean

U = Int(n ^ 0.5)
is_prime = True
i = 2

Do While is_prime And i <= U
If n Mod i = 0 Then
is_prime = False
End If

i = i + 1
Loop

End Function

P(n) = 5283234035979900n + 43142746595714191, n=0,1,2,3......,25

 歡迎光臨 Math Pro 數學補給站 (https://math.pro/db/) 論壇程式使用 Discuz! 6.1.0