Fermat numbers
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. Only the first eleven Fermat numbers have been completely factored, though many have been partially factored.
- Task
- Write a routine (function, procedure, whatever) to generate Fermat numbers.
- Use the routine to find and display here, on this page, the first 10 Fermat numbers - F0 through F9.
- Find and display here, on this page, the prime factors of as many Fermat numbers as you have patience for. (Or as many as can be found in five minutes or less of processing time). Note: if you make it past F11, there may be money, and certainly will be acclaim in it for you.
- See also
Perl 6
I gave up on factoring F₉ after about 20 minutes.
<lang perl6>use ntheory:from<Perl5> <factor>;
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' !!
}</lang>
- Output:
First 10 Fermat numbers: F₀ = 3 F₁ = 5 F₂ = 17 F₃ = 257 F₄ = 65537 F₅ = 4294967297 F₆ = 18446744073709551617 F₇ = 340282366920938463463374607431768211457 F₈ = 115792089237316195423570985008687907853269984665640564039457584007913129639937 F₉ = 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084097 Factors of first few Fermat numbers: Factors of F₀: 3 - prime Factors of F₁: 5 - prime Factors of F₂: 17 - prime Factors of F₃: 257 - prime Factors of F₄: 65537 - prime Factors of F₅: 641 6700417 Factors of F₆: 274177 67280421310721 Factors of F₇: 59649589127497217 5704689200685129054721 Factors of F₈: 1238926361552897 93461639715357977769163558199606896584051237541638188580280321