How to resolve the algorithm Fermat numbers step by step in the langur programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Fermat numbers step by step in the langur 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 langur programming language
Source code in the langur programming language
val .fermat = f 2 ^ 2 ^ .n + 1
val .factors = f(var .x) {
for[.f=[]] .i, .s = 2, truncate .x ^/ 2; .i < .s; .i += 1 {
if .x div .i {
.f ~= [.i]
.x \= .i
.s = truncate .x ^/ 2
}
} ~ [.x]
}
writeln "first 10 Fermat numbers"
for .i in 0..9 {
writeln $"F\(.i + 16x2080:cp) = \(.fermat(.i))"
}
writeln()
writeln "factors of first few Fermat numbers"
for .i in 0..9 {
val .ferm = .fermat(.i)
val .fac = .factors(.ferm)
if len(.fac) == 1 {
writeln $"F\(.i + 16x2080:cp) is prime"
} else {
writeln $"F\(.i + 16x2080:cp) factors: ", .fac
}
}
You may also check:How to resolve the algorithm CRC-32 step by step in the C# programming language
You may also check:How to resolve the algorithm Damm algorithm step by step in the Forth programming language
You may also check:How to resolve the algorithm Check that file exists step by step in the HicEst programming language
You may also check:How to resolve the algorithm Matrix digital rain step by step in the Ada programming language
You may also check:How to resolve the algorithm String comparison step by step in the Phix programming language