Let us pair the squares of the numbers 1 to n with the squares of the numbers n+1 to 2n such that each pair sums up to a prime.
1. Demonstrate that it is not possible for n1=3, n2=?(find out) and n3=??(find out)
2. For what value of n there are exactly 2 ways to perform the task?
Hint: all answers are below 15
The program below find no pairings possible for n=3, 6 or 11.
It also shows there are exactly 2 ways for n=5.
For n = 2 through 15 are shown the value of n, the pairing of squares for the first way of doing it (both pairings for n=5), followed by the number of pairings altogether, for example 140 valid pairings for n=15. Again, except for n=5, only the first pairing found is shown; the number of ways is shown below the shown pairing(s).
Within each shown pairing the first column shows 1 through n^2; the second column, the squares paired from (n+1)^2 through (2n)^2; then the total of those two squares.
n = 2
1 16 17
4 9 13
1
n = 3
0
n = 4
1 36 37
4 49 53
9 64 73
16 25 41
1
n = 5
1 36 37
4 49 53
9 100 109
16 81 97
25 64 89
1 100 101
4 49 53
9 64 73
16 81 97
25 36 61
2
n = 6
0
n = 7
1 196 197
4 169 173
9 100 109
16 81 97
25 64 89
36 121 157
49 144 193
1
n = 8
1 196 197
4 225 229
9 100 109
16 81 97
25 256 281
36 121 157
49 144 193
64 169 233
1
n = 9
1 196 197
4 169 173
9 100 109
16 225 241
25 324 349
36 121 157
49 144 193
64 289 353
81 256 337
4
n = 10
1 196 197
4 169 173
9 400 409
16 225 241
25 324 349
36 121 157
49 144 193
64 289 353
81 256 337
100 361 461
8
n = 11
0
n = 12
1 576 577
4 169 173
9 400 409
16 225 241
25 484 509
36 361 397
49 324 373
64 289 353
81 256 337
100 441 541
121 196 317
144 529 673
8
n = 13
1 196 197
4 225 229
9 400 409
16 441 457
25 576 601
36 361 397
49 324 373
64 529 593
81 256 337
100 289 389
121 676 797
144 625 769
169 484 653
42
n = 14
1 576 577
4 225 229
9 400 409
16 441 457
25 484 509
36 361 397
49 324 373
64 289 353
81 256 337
100 729 829
121 676 797
144 529 673
169 784 953
196 625 821
28
n = 15
1 256 257
4 289 293
9 400 409
16 441 457
25 576 601
36 841 877
49 324 373
64 529 593
81 676 757
100 729 829
121 900 1021
144 625 769
169 484 653
196 361 557
225 784 1009
140
DefDbl A-Z
Dim crlf$, sq(15), n, h(), used(), solct
Private Sub Form_Load()
Text1.Text = ""
crlf$ = Chr(13) + Chr(10)
Form1.Visible = True
For i = 1 To 15: sq(i) = i * i: Next
For n = 2 To 15
Text1.Text = Text1.Text & "n = " & n & crlf
ReDim h(n), used(n)
solct = 0
addOn 1
Text1.Text = Text1.Text & solct & crlf & crlf & crlf
Next
End Sub
Sub addOn(wh)
DoEvents
For i = 1 To n
If used(i) = 0 Then
p = sq(wh) + (n + i) * (n + i)
If prmdiv(p) = p Then
h(wh) = (n + i) * (n + i)
used(i) = 1
If wh = n Then
solct = solct + 1
If solct = 1 Or n = 5 Then
For j = 1 To wh
Text1.Text = Text1.Text & sq(j) & Str(h(j)) & Str(sq(j) + h(j)) & crlf
Next
Text1.Text = Text1.Text & crlf
End If
Else
addOn (wh + 1)
End If
used(i) = 0
End If
End If
Next
End Sub
Function prmdiv(num)
Dim n, dv, q
If num = 1 Then prmdiv = 1: Exit Function
n = Abs(num): If n > 0 Then limit = Sqr(n) Else limit = 0
If limit <> Int(limit) Then limit = Int(limit + 1)
dv = 2: GoSub DivideIt
dv = 3: GoSub DivideIt
dv = 5: GoSub DivideIt
dv = 7
Do Until dv > limit
GoSub DivideIt: dv = dv + 4 '11
GoSub DivideIt: dv = dv + 2 '13
GoSub DivideIt: dv = dv + 4 '17
GoSub DivideIt: dv = dv + 2 '19
GoSub DivideIt: dv = dv + 4 '23
GoSub DivideIt: dv = dv + 6 '29
GoSub DivideIt: dv = dv + 2 '31
GoSub DivideIt: dv = dv + 6 '37
Loop
If n > 1 Then prmdiv = n
Exit Function
DivideIt:
Do
q = Int(n / dv)
If q * dv = n And n > 0 Then
prmdiv = dv: Exit Function
Else
Exit Do
End If
Loop
Return
End Function
|
Posted by Charlie
on 2017-11-29 13:31:55 |