Quadrat special primes

From Rosetta Code
Revision as of 16:54, 28 March 2021 by CalmoSoft (talk | contribs) (Created page with "{{Draft task}} ;Task: '''n'''   is smallest prime such that the difference of successive terms is the smallest quadrat number, where     '''n'''   < &...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Quadrat special primes is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task

n   is smallest prime such that the difference of successive terms is the smallest quadrat number, where     n   <   16000.

Ring

<lang ring> load "stdlib.ring"

see "working..." + nl

flag = 1 Primes = [] limit1 = 50 oldPrime = 1

for n = 1 to limit1

   nextPrime = oldPrime + pow(n,2)
   if isprime(nextPrime)
      flag = 1
      n = 1
      add(Primes,nextPrime)
      oldPrime = nextPrime
   else
      flag = 0
      nextPrime = nextPrime - oldPrime
   ok

next

see "prime1 prime2 Gap" + nl for n = 1 to Len(Primes)-1

   diff = Primes[n+1] - Primes[n]
   see ""+ Primes[n] + "      " + Primes[n+1] + "    " + diff + nl

next

see nl + "done..." + nl </lang>

Output:
working...
prime1 prime2 Gap
2      11    9
11      47    36
47      83    36
83      227    144
227      263    36
263      587    324
587      911    324
911      947    36
947      983    36
983      1019    36
1019      1163    144
1163      1307    144
1307      1451    144
1451      1487    36
1487      1523    36
1523      1559    36
1559      2459    900
2459      3359    900
3359      4259    900
4259      4583    324
4583      5483    900
5483      5519    36
5519      5843    324
5843      5879    36
5879      6203    324
6203      6779    576
6779      7103    324
7103      7247    144
7247      7283    36
7283      7607    324
7607      7643    36
7643      8219    576
8219      8363    144
8363      10667    2304
10667      11243    576
11243      11279    36
11279      11423    144
11423      12323    900
12323      12647    324
12647      12791    144
12791      13367    576
13367      13691    324
13691      14591    900
14591      14627    36
14627      14771    144
14771      15671    900
done...