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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Quad-power prime seeds step by step in the Python 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 Python programming language

In this code the isquadpowerprime function checks if the given number is a quad-power prime root number, that is, if the number plus one, the number squared plus one, the number cubed plus one, and the number to the fourth power plus one are all prime numbers. The main part of the code then generates a list of all quad-power prime root numbers up to 10,100,000 and stores them in the qpprimes list. The first loop then prints out the first 50 quad-power prime root numbers, 10 numbers per line. The second loop then finds the first quad-power prime root number greater than each of the numbers 1,000,000, 2,000,000, ..., 10,000,000 and prints out the result.

Source code in the python programming language

""" quad-power prime root numbers """

from sympy import isprime


def isquadpowerprime(cand):
    """ return if is a quad power prime root number """
    return all(isprime(i) for i in
               [cand + cand + 1, cand**2 + cand + 1, cand**3 + cand + 1, cand**4 + cand + 1])


qpprimes = [k for k in range(10_100_000) if isquadpowerprime(k)]

for i in range(50):
    print(f'{qpprimes[i]: 9,}', end='\n' if (i + 1) % 10 == 0 else '')


for j in range(1_000_000, 10_000_001, 1_000_000):
    for p in qpprimes:
        if p > j:
            print(f'The first quad-power prime seed over {j:,} is {p:,}')
            break


  

You may also check:How to resolve the algorithm Chinese remainder theorem step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Accumulator factory step by step in the EMal programming language
You may also check:How to resolve the algorithm Averages/Pythagorean means step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Ascending primes step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Walk a directory/Recursively step by step in the Nim programming language