How to resolve the algorithm Fermat numbers step by step in the Raku programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Fermat numbers step by step in the Raku programming language
Table of Contents
Problem Statement
In mathematics, a Fermat number, named after Pierre de Fermat who first studied them, is a positive integer of the form Fn = 22n + 1 where n is a non-negative integer. Despite the simplicity of generating Fermat numbers, they have some powerful mathematical properties and are extensively used in cryptography & pseudo-random number generation, and are often linked to other number theoric fields. As of this writing, (mid 2019), there are only five known prime Fermat numbers, the first five (F0 through F4). Only the first twelve Fermat numbers have been completely factored, though many have been partially factored.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Fermat numbers step by step in the Raku programming language
Source code in the raku programming language
use ntheory:from ;
my @Fermats = (^Inf).map: 2 ** 2 ** * + 1;
my $sub = '₀';
say "First 10 Fermat numbers:";
printf "F%s = %s\n", $sub++, $_ for @Fermats[^10];
$sub = '₀';
say "\nFactors of first few Fermat numbers:";
for @Fermats[^9].map( {"$_".&factor} ) -> $f {
printf "Factors of F%s: %s %s\n", $sub++, $f.join(' '), $f.elems == 1 ?? '- prime' !! ''
}
You may also check:How to resolve the algorithm Empty program step by step in the Quackery programming language
You may also check:How to resolve the algorithm Currying step by step in the TXR programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bubble sort step by step in the JavaScript programming language
You may also check:How to resolve the algorithm A+B step by step in the PostScript programming language
You may also check:How to resolve the algorithm Sorting algorithms/Sleep sort step by step in the Sidef programming language