How to resolve the algorithm Primes: n*2^m+1 step by step in the Wren programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Primes: n*2^m+1 step by step in the Wren programming language

Table of Contents

Problem Statement

A050921 - Smallest prime of form n*2^m+1

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Primes: n*2^m+1 step by step in the Wren programming language

Source code in the wren programming language

import "./gmp" for Mpz
import "./fmt" for Fmt

System.print("  N     M    Prime")
System.print("------------------")
for (n in 1..400) {
    var m = 0
    while (true) {
        var p = Mpz.from(n).mul(Mpz.one.lsh(m)).add(1)
        if (p.probPrime(15) > 0) {
            Fmt.print("$3d  $4d    $20a", n, m, p)
            break
        }
        m = m + 1
    }
}

  

You may also check:How to resolve the algorithm Magic squares of singly even order step by step in the J programming language
You may also check:How to resolve the algorithm Walk a directory/Non-recursively step by step in the Hare programming language
You may also check:How to resolve the algorithm Averages/Median step by step in the Lua programming language
You may also check:How to resolve the algorithm Boolean values step by step in the Logo programming language
You may also check:How to resolve the algorithm Bulls and cows step by step in the Rust programming language