Data update

This commit is contained in:
Ingy döt Net 2023-12-16 21:33:55 -08:00
parent 35bcdeebf8
commit 74c69a0df6
2427 changed files with 31826 additions and 3468 deletions

View file

@ -0,0 +1,19 @@
fn main() {
const RANGE_MAX: u32 = 20_000;
let proper_divs = |n: u32| -> Vec<u32> {
(1..=(n + 1) / 2).filter(|&x| n % x == 0).collect()
};
let n2d: Vec<u32> = (1..=RANGE_MAX).map(|n| proper_divs(n).iter().sum()).collect();
for (n, &div_sum) in n2d.iter().enumerate() {
let n = n as u32 + 1;
if n < div_sum && div_sum <= RANGE_MAX && n2d[div_sum as usize - 1] == n {
println!("Amicable pair: {} and {} with proper divisors:", n, div_sum);
println!(" {:?}", proper_divs(n));
println!(" {:?}", proper_divs(div_sum));
}
}
}

View file

@ -0,0 +1,17 @@
program amicable_pairs;
p := propDivSums(20000);
loop for [n,m] in p | n = p(p(n)) and n<m do
print([n,m]);
end loop;
proc propDivSums(n);
divs := {};
loop for i in [1..n] do
loop for j in [i*2, i*3..n] do
divs(j) +:= i;
end loop;
end loop;
return divs;
end proc;
end program;

View file

@ -1,7 +1,7 @@
fn pfac_sum(i int) int {
mut sum := 0
for p := 1;p <= i/2;p++{
if i%p == 0 {
for p := 1; p <= i / 2; p++{
if i % p == 0 {
sum += p
}
}

View file

@ -1,5 +1,5 @@
import "/fmt" for Fmt
import "/math" for Int, Nums
import "./fmt" for Fmt
import "./math" for Int, Nums
var a = List.filled(20000, 0)
for (i in 1...20000) a[i] = Nums.sum(Int.properDivisors(i))
@ -7,6 +7,6 @@ System.print("The amicable pairs below 20,000 are:")
for (n in 2...19999) {
var m = a[n]
if (m > n && m < 20000 && n == a[m]) {
System.print(" %(Fmt.d(5, n)) and %(Fmt.d(5, m))")
Fmt.print(" $5d and $5d", n, m)
}
}