回復 1# 克勞棣 的帖子
利用版主的例子所給的提示:
公差 d = 3709 - 3499 = 409 - 199 = 210 = 2*3*5*7
再利用程式檢測首項10萬以內的質數: ( 2 ≤ a ≤ 100000 )
(1) d = 2*3*5*7 = 210
連續6項皆質數,首項a有87組解: a = 13, 47, 179, ..... , 98297
再從這87組解,篩選出連續11項皆質數者,結果無解.
(2) d = 2*3*5*7*11 = 2310
連續6項皆質數,首項a有158組解: a = 37, 71, 83, ..... , 99023
再從這158組解,篩選出連續11項皆質數者,結果無解.
(3) d = 2*3*5*7*11*13 = 30030
連續6項皆質數,首項a有120組解: a = 73, 619, 751, ..... , 98017
再從這120組解,篩選出連續11項皆質數者,結果有3組解: a = 23143, 53173, 75307
Ans: 若限定首項10萬以內的質數( 2 ≤ a ≤ 100000 ), 公差30030以內,
連續11項以上都是質數的等差數列有3組解:
( 首項 , 公差 ) = ( a, d ) = ( 23143, 30030 ) , ( 53173, 30030 ) , ( 75307, 30030 )
註解. Excel VBA 程式碼:
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