Abundant odd numbers: Difference between revisions

m (added a link to an OEIS reference.)
Line 2,244:
First odd abundant number over 10^9, with its divisor sum:
(1000000575, 1083561009)</pre>
 
=={{header|R}}==
<lang R># Abundant Odd Numbers
 
find_div_sum <- function(x){
# Finds sigma: the sum of the divisors (not including the number itself) of an odd number
if (x < 16) return(0)
root <- sqrt(x)
vec <- as.vector(1)
for (i in seq.int(3, root - 1, by = 2)){
if(x %% i == 0){
vec <- c(vec, i, x/i)
}
}
if (root == trunc(root)) vec = c(vec, root)
return(sum(vec))
}
 
get_n_abun <- function(index = 1, total = 25, print_all = TRUE){
# Finds a total of 'total' abundant odds starting with 'index', with print option
n <- 1
while(n <= total){
my_sum <- find_div_sum(index)
if (my_sum > index){
if(print_all) cat(index, "..... sigma is", my_sum, "\n")
n <- n + 1
}
index <- index + 2
}
if(!print_all) cat(index - 2, "..... sigma is", my_sum, "\n")
}
 
# Get first 25
cat("The first 25 abundants are")
get_n_abun()
 
# Get the 1000th
cat("The 1000th odd abundant is")
get_n_abun(total = 1000, print_all = F)
 
# Get the first after 1e9
cat("First odd abundant after 1e9 is")
get_n_abun(index = 1e9 + 1, total = 1, print_all = F)</lang>
 
{{Out}}
<pre>The first 25 abundants are
945 ..... sigma is 975
1575 ..... sigma is 1649
2205 ..... sigma is 2241
2835 ..... sigma is 2973
3465 ..... sigma is 4023
4095 ..... sigma is 4513
4725 ..... sigma is 5195
5355 ..... sigma is 5877
5775 ..... sigma is 5977
5985 ..... sigma is 6495
6435 ..... sigma is 6669
6615 ..... sigma is 7065
6825 ..... sigma is 7063
7245 ..... sigma is 7731
7425 ..... sigma is 7455
7875 ..... sigma is 8349
8085 ..... sigma is 8331
8415 ..... sigma is 8433
8505 ..... sigma is 8967
8925 ..... sigma is 8931
9135 ..... sigma is 9585
9555 ..... sigma is 9597
9765 ..... sigma is 10203
10395 ..... sigma is 12645
11025 ..... sigma is 11946
 
The 1000th odd abundant is
492975 ..... sigma is 519361
 
First odd abundant after 1e9 is
1000000575 ..... sigma is 1083561009</pre>
 
=={{header|Racket}}==
Anonymous user