Fermat numbers: Difference between revisions

m (→‎{{header|ALGOL 68}}: Remove unnecessary ;)
(3 intermediate revisions by 2 users not shown)
Line 26:
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Uses Algol 68G's LONG LONG INT which has programmer specifiable precision.
{{libheader|ALGOL 68-primes}}
The source of primes.incl.a68 is on another page on Rosetta Code, see the above link.
Line 1,377 ⟶ 1,379:
=={{header|langur}}==
{{trans|Python}}
<syntaxhighlight lang="langur">val .fermat = ffn .i: 2 ^ 2 ^ .i + 1
 
val .factors = ffn(var .x) {
for[.f=[]] .i, .s = 2, trunc .x ^/ 2; .i < .s; .i += 1 {
if .x div .i {
Line 1,391 ⟶ 1,393:
writeln "first 10 Fermat numbers"
for .i in 0..9 {
writeln $"F\({{.i + 16x2080:cp)}} = \({{.fermat(.i))}}"
}
writeln()
Line 1,400 ⟶ 1,402:
val .fac = .factors(.ferm)
if len(.fac) == 1 {
writeln $"F\({{.i + 16x2080:cp)}} is prime"
} else {
writeln $"F\({{.i + 16x2080:cp)}} factors: ", {{.fac}}"
}
}
}</syntaxhighlight>
 
{{out}}
I just ran an initial test. Maybe I'll take the time to calculate more factors later.
<pre>first 10 Fermat numbers
F₀ = 3
990

edits