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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Wagstaff primes step by step in the XPL0 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 XPL0 programming language

Source code in the xpl0 programming language

func IsPrime(N);        \Return 'true' if N is prime
real N;  int  I;
[if N <= 2. then return N = 2.;
if Mod(N, 2.) = 0. then \even\ return false;
for I:= 3 to fix(sqrt(N)) do
    [if Mod(N, float(I)) = 0. then return false;
    I:= I+1;
    ];
return true;
];

real P, Q;  int C;
[P:= 2.;  C:= 0;
Format(1, 0);
repeat  if IsPrime(P) then
            [Q:= Pow(2., P) + 1.;
            if Mod(Q, 3.) = 0. and IsPrime(Q/3.) then
                [Text(0, "(2^^");
                RlOut(0, P);
                Text(0, " + 1)/3 = ");
                RlOut(0, Q/3.);
                CrLf(0);
                C:= C+1;
                ];
            ];
        P:= P+1.;
until   C >= 10;
]

  

You may also check:How to resolve the algorithm Count in factors step by step in the NetRexx programming language
You may also check:How to resolve the algorithm Extend your language step by step in the XBS programming language
You may also check:How to resolve the algorithm Sudan function step by step in the Swift programming language
You may also check:How to resolve the algorithm Comments step by step in the Insitux programming language
You may also check:How to resolve the algorithm Forward difference step by step in the Julia programming language