How to resolve the algorithm Quad-power prime seeds step by step in the Nim programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Quad-power prime seeds step by step in the Nim programming language

Table of Contents

Problem Statement

Generate the sequence of quad-power prime seeds: positive integers n such that:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Quad-power prime seeds step by step in the Nim programming language

Source code in the nim programming language

import std/[strformat, strutils]
import integers

func isQuadPowerPrimeSeeds(n: Integer): bool =
  var p = newInteger(n)
  var n1 = n + 1
  for _ in 1..4:
    if not isPrime(p + n1): return false
    p *= n
  result = true

const N = 1_000_000

echo "First 30 quad-power prime seeds:"
var count = 0
var n = 1
var limit = N
while true:
  if n.isQuadPowerPrimeSeeds():
    inc count
    if count <= 50:
      stdout.write &"{n:7}"
      stdout.write if count mod 10 == 0: '\n' else: ' '
      if count == 50: echo()
    elif n > limit:
      echo &"First quad-power prime seed greater than {insertSep($limit)} " &
           &"is {insertSep($n)} at position {count}."
      inc limit, N
      if limit > 3 * N: break
  inc n


  

You may also check:How to resolve the algorithm Minimal steps down to 1 step by step in the C# programming language
You may also check:How to resolve the algorithm Loops/For step by step in the ActionScript programming language
You may also check:How to resolve the algorithm MAC vendor lookup step by step in the Java programming language
You may also check:How to resolve the algorithm Array concatenation step by step in the FBSL programming language
You may also check:How to resolve the algorithm Percentage difference between images step by step in the MATLAB programming language