Meissel–Mertens constant: Difference between revisions

Added Easylang
m (Minor improvement to code.)
(Added Easylang)
 
(4 intermediate revisions by 3 users not shown)
Line 447:
{{out}}
<pre>MM = 0.2614972131057144</pre>
 
=={{header|EasyLang}}==
{{trans|BASIC256}}
<syntaxhighlight>
fastfunc isprim num .
if num mod 2 = 0
if num = 2
return 1
.
return 0
.
i = 3
while i <= sqrt num
if num mod i = 0
return 0
.
i += 2
.
return 1
.
func log x .
return log10 x / log10 2.7182818284590452354
.
euler = 0.5772156649
for x = 2 to 1e6
if isprim x = 1
m += log (1 - (1 / x)) + (1 / x)
.
.
numfmt 11 0
print "mm = " & euler + m
</syntaxhighlight>
 
{{out}}
<pre>
mm = 0.26149724673
</pre>
 
=={{header|FreeBASIC}}==
Line 573 ⟶ 610:
 
}
</syntaxhighlight>
{{ out }}
<pre>
Line 591 ⟶ 629:
@show meissel_mertens(100_000_000) # meissel_mertens(100000000) = 0.2614972128591237
</syntaxhighlight>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
meissel_mertens:%gamma+lsum(log(1-(1/i))+(1/i),i,primes(2,10000000)),numer;
</syntaxhighlight>
{{out}}
<pre>
0.2614972157776471
</pre>
 
=={{header|Nim}}==
Line 704 ⟶ 751:
{{libheader|ntheory}}
<syntaxhighlight lang="perl" line>use v5.36;
use ntheory 'is_prime'qw(forprimes);
 
my $s;
is_primeforprimes $_ and{ $s += log(1 - 1/$_)+1/$_ for 2 ..} 10**91e9;
say my $result = $s + .57721566490153286;</syntaxhighlight>
{{out}}
Line 874 ⟶ 921:
<pre>
1: 0.262733140866
</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">var sum = 0
1e7.each_prime {|p|
with (1f/p) {|t|
sum += (log(1 - t) + t)
}
}
say sum+Num.EulerGamma</syntaxhighlight>
{{out}}
<pre>
0.26149721577767111119422410228297206467931376306
</pre>
 
Line 881 ⟶ 941:
{{libheader|Wren-fmt}}
It will be seen that this is converging to the correct answer though we'd need to add a lot more primes to obtain a valid 11th digit.
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./fmt" for Fmt
 
Line 918 ⟶ 978:
{{libheader|Wren-gmp}}
This agrees with the Phix entry that the 1,000th digit after the decimal point is '8' after rounding (according to OEIS it's actually '7' but the next one is '7' also).
<syntaxhighlight lang="ecmascriptwren">import "./gmp" for Mpf
import "./math" for Int
import "./fmt" for Fmt
2,052

edits