Find adjacent primes which differ by a square integer

From Rosetta Code
Revision as of 12:29, 21 November 2021 by CalmoSoft (talk | contribs) (Created page with "{{Draft task}} ;Task: <br>Find adjacents primes which differece is square integer under '''1,000,000''' <br><br> =={{header|Ring}}== <lang ring> load "stdlib.ring" see "work...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Find adjacent primes which differ by a square integer 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


Find adjacents primes which differece is square integer under 1,000,000

Ring

<lang ring> load "stdlib.ring" see "working..." + nl limit = 1000000 Primes = [] oldPrime = 0 newPrime = 0 x = 0

for n = 1 to limit

   if isprime(n)
      add(Primes,n)
   ok

next

for n = 2 to len(Primes)

   pr1 = Primes[n]
   pr2 = Primes[n-1]
   diff = pr1 - pr2
   flag = issquare(diff)
   if flag = 1 and diff > 36
      see "" + pr1 + " " + pr2 + " diff = " + diff + nl
   ok

next

see "done..." + nl

func issquare(x)

    for n = 1 to sqrt(x)
        if x = pow(n,2)
           return 1
        ok
    next
    return 0

</lang>

Output:
working...
89753 89689 diff = 64
107441 107377 diff = 64
288647 288583 diff = 64
368021 367957 diff = 64
381167 381103 diff = 64
396833 396733 diff = 100
400823 400759 diff = 64
445427 445363 diff = 64
623171 623107 diff = 64
625763 625699 diff = 64
637067 637003 diff = 64
710777 710713 diff = 64
725273 725209 diff = 64
779477 779413 diff = 64
801947 801883 diff = 64
803813 803749 diff = 64
821741 821677 diff = 64
832583 832519 diff = 64
838349 838249 diff = 100
844841 844777 diff = 64
883871 883807 diff = 64
912167 912103 diff = 64
919511 919447 diff = 64
954827 954763 diff = 64
981887 981823 diff = 64
997877 997813 diff = 64
done...