All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Just a search (Posted on 2018-08-18) Difficulty: 4 of 5
List all prime numbers below 3000 that can be expressed
as a^2 + n*b^2 for all integer n's from 1 to 10.

No Solution Yet Submitted by Ady TZIDON    
No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution | Comment 3 of 5 |
These are the numbers below 3000 that can be so formed:

(I interpreted this as that each one must be expressible using each n from 1 to 10, not just one of those.)

1009
1129
1201
1801
2521
2689

The specifics:

prime  a   n   b

1009  15   1  28
1009  28   1  15
1009  19   2  18
1009  31   3   4
1009  15   4  14
1009  17   5  12
1009  25   6   8
1009   1   7  12
1009  19   8   9
1009  28   9   5
1009   3  10  10

1129  20   1  27
1129  27   1  20
1129  29   2  12
1129  19   3  16
1129  27   4  10
1129   2   5  15
1129  23   6  10
1129  11   7  12
1129  29   8   6
1129  20   9   9
1129  33  10   2

1201  24   1  25
1201  25   1  24
1201   7   2  24
1201   1   3  20
1201  25   4  12
1201  34   5   3
1201   5   6  14
1201  33   7   4
1201   7   8  12
1201  25   9   8
1201  29  10   6

1801  24   1  35
1801  35   1  24
1801   1   2  30
1801  37   3  12
1801  35   4  12
1801  26   5  15
1801  25   6  14
1801   3   7  16
1801   1   8  15
1801  35   9   8
1801  19  10  12

2521  35   1  36
2521  36   1  35
2521  37   2  24
2521  13   3  28
2521  35   4  18
2521  46   5   9
2521  11   6  20
2521  27   7  16
2521  37   8  12
2521  35   9  12
2521  39  10  10

2689  33   1  40
2689  40   1  33
2689  49   2  12
2689  31   3  24
2689  33   4  20
2689  22   5  21
2689  17   6  20
2689  41   7  12
2689  49   8   6
2689  40   9  11
2689  27  10  14

DefDbl A-Z
Dim crlf$, soln(100)
Function mform$(x, t$)
  a$ = Format$(x, t$)
  If Len(a$) < Len(t$) Then a$ = Space$(Len(t$) - Len(a$)) & a$
  mform$ = a$
End Function

Private Sub Form_Load()
 Text1.Text = ""
 crlf$ = Chr(13) + Chr(10)
 Form1.Visible = True
  
 Do
   p = nxtprm(p)
   good1 = 1
   For n = 1 To 10
    good = 0
    For a = 0 To Sqr(p)
     a2 = a * a
     diff = p - a2
     b = Int(Sqr(diff / n) + 0.5)
     If b * b * n = diff Then good = 1: Exit For
    Next a
    If good = 0 Then good1 = 0
   Next n
   If good1 Then
       Text1.Text = Text1.Text & p & crlf
       goodct = goodct + 1
       soln(goodct) = p
   End If
   DoEvents
 Loop Until p > 3000
 
 p = 0
 
  Do
   p = nxtprm(p)
   good1 = 1
   For n = 1 To 10
    good = 0
    For a = 0 To Sqr(p)
     a2 = a * a
     diff = p - a2
     b = Int(Sqr(diff / n) + 0.5)
     If b * b * n = diff Then
       oneOfThem = 0
       For i = 1 To goodct
         If soln(i) = p Then
           Text1.Text = Text1.Text & p & mform(a, "###0") & mform(n, "###0") & mform(b, "###0") & crlf
         End If
       Next
     End If
    Next a
    If good = 0 Then good1 = 0
   Next n
   If good1 Then
       Text1.Text = Text1.Text & p & crlf
       goodct = goodct + 1
       soln(goodct) = p
   End If
   DoEvents
 Loop Until p > 3000

  
  Text1.Text = Text1.Text & " done"
  
  
  End Sub
Function prm(i)
  Dim p As Long
  Open "17-bit primes.bin" For Random As #111 Len = 4
  Get #111, i, p
  prm = p
  Close 111
End Function
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
Function nxtprm(x)
  Dim n
  n = x + 1
  While prmdiv(n) < n Or n < 2
    n = n + 1
  Wend
  nxtprm = n
End Function


  Posted by Charlie on 2018-08-18 14:36:33
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (0)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information