Data update

This commit is contained in:
Ingy döt Net 2024-03-06 22:25:12 -08:00
parent ed705008a8
commit 0df55f9f24
2196 changed files with 32999 additions and 3075 deletions

View file

@ -0,0 +1,114 @@
PROGRAM CHOWLA
CALL PUT_1ST_37
CALL PUT_PRIME
CALL PUT_PERFECT
END
INTEGER*4 FUNCTION CHOWLA1(N)
C The Chowla number of N is the sum of the divisors of N
C excluding unity and N where N is a positive integer
IMPLICIT INTEGER*4 (A-Z)
IF (N .LE. 0) STOP 'Argument to Chowla function must be > 0'
SUM = 0
I = 2
100 CONTINUE
IF (I * I .GT. N) GOTO 200
IF (MOD(N, I) .NE. 0) GOTO 110
J = N / I
SUM = SUM + I
IF ( I .NE. J) SUM = SUM + J
110 CONTINUE
I = I + 1
GOTO 100
200 CONTINUE
CHOWLA1 = SUM
RETURN
END
SUBROUTINE PUT_1ST_37
IMPLICIT INTEGER*4 (A-Z)
DO 100 I = 1, 37
PRINT 900, I, CHOWLA1(I)
100 CONTINUE
RETURN
900 FORMAT(1H , 'CHOWLA(', I2, ') = ', I2)
END
SUBROUTINE PUT_PRIME
IMPLICIT INTEGER*4 (A-Z)
PARAMETER LIMIT = 10000000
COUNT = 0
POWER = 100
DO 200 N = 2, LIMIT
IF (CHOWLA1(N) .EQ. 0) COUNT = COUNT + 1
IF (MOD(N, POWER) .NE. 0) GOTO 100
PRINT 900, COUNT, POWER
POWER = POWER * 10
100 CONTINUE
200 CONTINUE
RETURN
900 FORMAT(1H ,'There are ', I12, ' primes < ', I12)
END
SUBROUTINE PUT_PERFECT
IMPLICIT INTEGER*4 (A-Z)
PARAMETER LIMIT = 35000000
COUNT = 0
K = 2
KK = 3
100 CONTINUE
P = K * KK
IF (P .GT. LIMIT) GOTO 300
IF (CHOWLA1(P) .NE. P - 1) GOTO 200
PRINT 900, P
COUNT = COUNT + 1
200 CONTINUE
K = KK + 1
KK = KK + K
GOTO 100
300 CONTINUE
PRINT 910, COUNT, LIMIT
RETURN
900 FORMAT(1H , I10, ' is a perfect number')
910 FORMAT(1H , 'There are ', I10, ' perfect numbers < ', I10)
END

View file

@ -0,0 +1,28 @@
chowla(n) = {
if (n < 1, error("Chowla function argument must be positive"));
if (n < 4, return(0));
my(divs = divisors(n));
sum(i=1, #divs, divs[i]) - n - 1;
}
\\ Function to count Chowla numbers
countchowlas(n, asperfect = 1, verbose = 1) = {
my(count = 0, chow, i);
for (i = 2, n,
chow = chowla(i);
if ( (asperfect && (chow == i - 1)) || ((!asperfect) && (chow == 0)),
count++;
if (verbose, print("The number " i " is " if (asperfect, "perfect.", "prime.")));
);
);
count;
}
\\ Main execution block
{
print("The first 37 chowla numbers are:");
for (i = 1, 37, printf("Chowla(%s) is %s\n", Str(i), Str(chowla(i)) ) );
m=100;
while(m<=10000000, print("The count of the primes up to " m " is " countchowlas(m, 0, 0)); m=m*10);
print("The count of perfect numbers up to 35,000,000 is " countchowlas(35000000, 1, 1));
}

View file

@ -0,0 +1,69 @@
fn chowla(n: usize) -> usize {
let mut sum = 0;
let mut i = 2;
while i * i <= n {
if n % i == 0 {
sum += i;
let j = n / i;
if i != j {
sum += j;
}
}
i += 1;
}
sum
}
fn sieve(limit: usize) -> Vec<bool> {
let mut c = vec![false; limit];
let mut i = 3;
while i * i < limit {
if !c[i] && chowla(i) == 0 {
let mut j = 3 * i;
while j < limit {
c[j] = true;
j += 2 * i;
}
}
i += 2;
}
c
}
fn main() {
for i in 1..=37 {
println!("chowla({}) = {}", i, chowla(i));
}
let mut count = 1;
let limit = 1e7 as usize;
let mut power = 100;
let c = sieve(limit);
for i in (3..limit).step_by(2) {
if !c[i] {
count += 1;
}
if i == power - 1 {
println!("Count of primes up to {} = {}", power, count);
power *= 10;
}
}
count = 0;
let limit = 35000000;
let mut k = 2;
let mut kk = 3;
loop {
let p = k * kk;
if p > limit {
break;
}
if chowla(p) == p - 1 {
println!("{} is a number that is perfect", p);
count += 1;
}
k = kk + 1;
kk += k;
}
println!("There are {} perfect numbers <= 35,000,000", count);
}