How to resolve the algorithm Wagstaff primes step by step in the Perl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Wagstaff primes step by step in the Perl programming language

Table of Contents

Problem Statement

A Wagstaff prime is a prime number of the form (2^p + 1)/3 where the exponent p is an odd prime. (2^5 + 1)/3 = 11 is a Wagstaff prime because both 5 and 11 are primes. Find and show here the first 10 Wagstaff primes and their corresponding exponents p. Find and show here the exponents p corresponding to the next 14 Wagstaff primes (not the primes themselves) and any more that you have the patience for. When testing for primality, you may use a method which determines that a large number is probably prime with reasonable certainty. It can be shown (see talk page) that (2^p + 1)/3 is always integral if p is odd. So there's no need to check for that prior to checking for primality.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Wagstaff primes step by step in the Perl programming language

Source code in the perl programming language

use v5.36;
use bigint;
use ntheory 'is_prime';

sub abbr ($d) { my $l = length $d; $l < 61 ? $d : substr($d,0,30) . '..' . substr($d,-30) . " ($l digits)" }

my($p,@W) = 2;
until (@W == 30) {
    next unless 0 != ++$p % 2;
    push @W, $p if is_prime($p) and is_prime((2**$p + 1)/3)
}

printf "%2d: %5d - %s\n", $_+1, $W[$_], abbr( (2**$W[$_] + 1) / 3) for 0..$#W;


  

You may also check:How to resolve the algorithm Van Eck sequence step by step in the Factor programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Read entire file step by step in the Odin programming language
You may also check:How to resolve the algorithm Perfect numbers step by step in the ooRexx programming language
You may also check:How to resolve the algorithm SHA-256 Merkle tree step by step in the Perl programming language