Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
2
Task/Mertens-function/Sidef/mertens-function-1.sidef
Normal file
2
Task/Mertens-function/Sidef/mertens-function-1.sidef
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
say mertens(123456789) #=> 1170
|
||||
say mertens(1234567890) #=> 9163
|
||||
35
Task/Mertens-function/Sidef/mertens-function-2.sidef
Normal file
35
Task/Mertens-function/Sidef/mertens-function-2.sidef
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
func mertens(n) is cached {
|
||||
|
||||
var lookup_size = (2 * n.iroot(3)**2)
|
||||
var mertens_lookup = [0]
|
||||
|
||||
for k in (1..lookup_size) {
|
||||
mertens_lookup[k] = (mertens_lookup[k-1] + k.moebius)
|
||||
}
|
||||
|
||||
static cache = Hash()
|
||||
|
||||
func (n) {
|
||||
|
||||
if (n <= lookup_size) {
|
||||
return mertens_lookup[n]
|
||||
}
|
||||
|
||||
if (cache.has(n)) {
|
||||
return cache{n}
|
||||
}
|
||||
|
||||
var M = 1
|
||||
var s = n.isqrt
|
||||
|
||||
for k in (2 .. floor(n/(s+1))) {
|
||||
M -= __FUNC__(floor(n/k))
|
||||
}
|
||||
|
||||
for k in (1..s) {
|
||||
M -= (mertens_lookup[k] * (floor(n/k) - floor(n/(k+1))))
|
||||
}
|
||||
|
||||
cache{n} = M
|
||||
}(n)
|
||||
}
|
||||
12
Task/Mertens-function/Sidef/mertens-function-3.sidef
Normal file
12
Task/Mertens-function/Sidef/mertens-function-3.sidef
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
with (200) {|n|
|
||||
say "Mertens function in the range 1..#{n}:"
|
||||
(1..n).map { mertens(_) }.slices(20).each {|line|
|
||||
say line.map{ "%2s" % _ }.join(' ')
|
||||
}
|
||||
}
|
||||
|
||||
with (1000) {|n|
|
||||
say "\nIn the range 1..#{n}, there are:"
|
||||
say (1..n->count_by { mertens(_)==0 }, " zeros")
|
||||
say (1..n->count_by { mertens(_)==0 && mertens(_-1)!=0 }, " zero crossings")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue