Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
34
Task/M-bius-function/Amazing-Hopper/m-bius-function.hopper
Normal file
34
Task/M-bius-function/Amazing-Hopper/m-bius-function.hopper
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include <basico.h>
|
||||
|
||||
#proto cálculodeMobius(_X_)
|
||||
#synon _cálculodeMobius calcularMobius
|
||||
|
||||
algoritmo
|
||||
|
||||
imprimir ("Mobius numbers from 1..199\n")
|
||||
i=0, s=1
|
||||
iterar grupo( ++i, #(i<=199), calcular Mobius (i), \
|
||||
solo si (#( iszero(s%20) ), NL;s=0 ), imprimir, ++s )
|
||||
saltar
|
||||
terminar
|
||||
|
||||
subrutinas
|
||||
|
||||
cálculo de Mobius (n)
|
||||
si( #(n==0) ) ; tomar '" "'
|
||||
sino si( #(n==1) ); tomar '" 1"'
|
||||
sino; p=0
|
||||
iterar para (i=1, #(i<=n+1), ++i)
|
||||
si ( #( iszero(n%i) && isprime(i)) )
|
||||
cuando ( #( iszero(n%(i*i)) ) ){
|
||||
tomar '" 0"'; ir a (herejía) /* ¡! */
|
||||
} ++p
|
||||
fin si
|
||||
siguiente
|
||||
tomar si ( es impar(p), " -1", " 1" )
|
||||
fin si
|
||||
|
||||
/* ¡Dios! ¡Purifica esta mierda! ----+ */
|
||||
/* | */
|
||||
herejía: /* <----------------------+ */
|
||||
retornar
|
||||
34
Task/M-bius-function/EasyLang/m-bius-function.easy
Normal file
34
Task/M-bius-function/EasyLang/m-bius-function.easy
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
mu_max = 100000
|
||||
sqroot = floor sqrt mu_max
|
||||
#
|
||||
for i to mu_max
|
||||
mu[] &= 1
|
||||
.
|
||||
for i = 2 to sqroot
|
||||
if mu[i] = 1
|
||||
for j = i step i to mu_max
|
||||
mu[j] *= -i
|
||||
.
|
||||
for j = i * i step i * i to mu_max
|
||||
mu[j] = 0
|
||||
.
|
||||
.
|
||||
.
|
||||
for i = 2 to mu_max
|
||||
if mu[i] = i
|
||||
mu[i] = 1
|
||||
elif mu[i] = -i
|
||||
mu[i] = -1
|
||||
elif mu[i] < 0
|
||||
mu[i] = 1
|
||||
elif mu[i] > 0
|
||||
mu[i] = -1
|
||||
.
|
||||
.
|
||||
numfmt 0 3
|
||||
for i = 1 to 100
|
||||
write mu[i]
|
||||
if i mod 10 = 0
|
||||
print ""
|
||||
.
|
||||
.
|
||||
|
|
@ -1 +1 @@
|
|||
mu=: ({{*/1-y>1}} * _1 ^ 2|+/)@q:~&_
|
||||
mu=: */@:-@~:@q:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
mu 1+i.10 20
|
||||
mu >: i. 10 20
|
||||
1 _1 _1 0 _1 1 _1 0 0 1 _1 0 _1 1 1 0 _1 0 _1 0
|
||||
1 1 _1 0 0 1 0 0 _1 _1 _1 0 1 1 1 0 _1 1 1 0
|
||||
_1 _1 _1 0 0 1 _1 0 0 0 1 0 _1 0 1 0 1 1 _1 0
|
||||
|
|
|
|||
78
Task/M-bius-function/Rust/m-bius-function.rust
Normal file
78
Task/M-bius-function/Rust/m-bius-function.rust
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
fn moebius(mut x: u64) -> i8 {
|
||||
let mut prime_count = 0;
|
||||
|
||||
// If x is divisible by the given factor this macro counts the factor and divides it out.
|
||||
// It then returns zero if x is still divisible by the factor.
|
||||
macro_rules! divide_x_by {
|
||||
($factor:expr) => {
|
||||
if x % $factor == 0 {
|
||||
x /= $factor;
|
||||
prime_count += 1;
|
||||
if x % $factor == 0 {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Handle 2 and 3 separately,
|
||||
divide_x_by!(2);
|
||||
divide_x_by!(3);
|
||||
|
||||
// then use a wheel sieve to check the remaining factors <= √x.
|
||||
for i in (5..=isqrt(x)).step_by(6) {
|
||||
divide_x_by!(i);
|
||||
divide_x_by!(i + 2);
|
||||
}
|
||||
|
||||
// There can exist one prime factor larger than √x,
|
||||
// in that case we can check if x is still larger than one, and then count it.
|
||||
if x > 1 {
|
||||
prime_count += 1;
|
||||
}
|
||||
|
||||
if prime_count % 2 == 0 {
|
||||
1
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the largest integer smaller than or equal to `√n`
|
||||
const fn isqrt(n: u64) -> u64 {
|
||||
if n <= 1 {
|
||||
n
|
||||
} else {
|
||||
let mut x0 = u64::pow(2, n.ilog2() / 2 + 1);
|
||||
let mut x1 = (x0 + n / x0) / 2;
|
||||
while x1 < x0 {
|
||||
x0 = x1;
|
||||
x1 = (x0 + n / x0) / 2;
|
||||
}
|
||||
x0
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
const ROWS: u64 = 10;
|
||||
const COLS: u64 = 20;
|
||||
println!(
|
||||
"Values of the Möbius function, μ(x), for x between 0 and {}:",
|
||||
COLS * ROWS
|
||||
);
|
||||
for i in 0..ROWS {
|
||||
for j in 0..=COLS {
|
||||
let x = COLS * i + j;
|
||||
let μ = moebius(x);
|
||||
if μ >= 0 {
|
||||
// Print an extra space if there's no minus sign in front of the output
|
||||
// in order to align the numbers in a nice grid.
|
||||
print!(" ");
|
||||
}
|
||||
print!("{μ} ");
|
||||
}
|
||||
println!();
|
||||
}
|
||||
let x = u64::MAX;
|
||||
println!("\nμ({x}) = {}", moebius(x));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue