Abundant odd numbers
An Abundant number is a number n for which the sum of divisors σ(n) > 2n, or, equivalently, the sum of proper divisors (or aliquot sum) s(n) > n.
E.G. 12 is abundant, it has the proper divisors 1,2,3,4 & 6 which sum to 16 ( > 12 or n); or alternately, has the sigma sum of 1,2,3,4,6 & 12 which sum to 28 ( > 24 or 2n ).
Abundant numbers are common, though even abundant numbers seem to be much more common than odd abundant numbers. To make things more interesting, this task is specifically about finding odd abundant numbers.
- Task
- Find and display here: at least the first 25 abundant odd numbers and either their proper divisor sum or sigma sum.
- Find and display here: the one thousandth abundant odd number and either its proper divisor sum / sigma sum.
- Find and display here: the first abundant odd number greater than one billion (109) and either its proper divisor sum or sigma sum.
Go
<lang go>package main
import (
"fmt" "strconv"
)
func divisors(n int) []int {
divs := []int{1} divs2 := []int{} for i := 2; i*i <= n; i++ { if n%i == 0 { j := n / i divs = append(divs, i) if i != j { divs2 = append(divs2, j) } } } for i := len(divs2) - 1; i >= 0; i-- { divs = append(divs, divs2[i]) } return divs
}
func sum(divs []int) int {
tot := 0 for _, div := range divs { tot += div } return tot
}
func sumStr(divs []int) string {
s := "" for _, div := range divs { s += strconv.Itoa(div) + " + " } return s[0 : len(s)-3]
}
func abundantOdd(searchFrom, countFrom, countTo int, printOne bool) int {
count := countFrom n := searchFrom for ; count < countTo; n += 2 { divs := divisors(n) if tot := sum(divs); tot > n { count++ if printOne && count < countTo { continue } s := sumStr(divs) if !printOne { fmt.Printf("%2d. %5d < %s = %d\n", count, n, s, tot) } else { fmt.Printf("%d < %s = %d\n", n, s, tot) } } } return n
}
func main() {
const max = 25 fmt.Println("The first", max, "abundant odd numbers are:") n := abundantOdd(1, 0, 25, false)
fmt.Println("\nThe one thousandth abundant odd number is:") abundantOdd(n, 25, 1000, true)
fmt.Println("\nThe first abundant odd number above one billion is:") abundantOdd(1e9+1, 0, 1, true)
}</lang>
- Output:
The first 25 abundant odd numbers are: 1. 945 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 105 + 135 + 189 + 315 = 975 2. 1575 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 175 + 225 + 315 + 525 = 1649 3. 2205 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 35 + 45 + 49 + 63 + 105 + 147 + 245 + 315 + 441 + 735 = 2241 4. 2835 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 81 + 105 + 135 + 189 + 315 + 405 + 567 + 945 = 2973 5. 3465 < 1 + 3 + 5 + 7 + 9 + 11 + 15 + 21 + 33 + 35 + 45 + 55 + 63 + 77 + 99 + 105 + 165 + 231 + 315 + 385 + 495 + 693 + 1155 = 4023 6. 4095 < 1 + 3 + 5 + 7 + 9 + 13 + 15 + 21 + 35 + 39 + 45 + 63 + 65 + 91 + 105 + 117 + 195 + 273 + 315 + 455 + 585 + 819 + 1365 = 4641 7. 4725 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 27 + 35 + 45 + 63 + 75 + 105 + 135 + 175 + 189 + 225 + 315 + 525 + 675 + 945 + 1575 = 5195 8. 5355 < 1 + 3 + 5 + 7 + 9 + 15 + 17 + 21 + 35 + 45 + 51 + 63 + 85 + 105 + 119 + 153 + 255 + 315 + 357 + 595 + 765 + 1071 + 1785 = 5877 9. 5775 < 1 + 3 + 5 + 7 + 11 + 15 + 21 + 25 + 33 + 35 + 55 + 75 + 77 + 105 + 165 + 175 + 231 + 275 + 385 + 525 + 825 + 1155 + 1925 = 6129 10. 5985 < 1 + 3 + 5 + 7 + 9 + 15 + 19 + 21 + 35 + 45 + 57 + 63 + 95 + 105 + 133 + 171 + 285 + 315 + 399 + 665 + 855 + 1197 + 1995 = 6495 11. 6435 < 1 + 3 + 5 + 9 + 11 + 13 + 15 + 33 + 39 + 45 + 55 + 65 + 99 + 117 + 143 + 165 + 195 + 429 + 495 + 585 + 715 + 1287 + 2145 = 6669 12. 6615 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 49 + 63 + 105 + 135 + 147 + 189 + 245 + 315 + 441 + 735 + 945 + 1323 + 2205 = 7065 13. 6825 < 1 + 3 + 5 + 7 + 13 + 15 + 21 + 25 + 35 + 39 + 65 + 75 + 91 + 105 + 175 + 195 + 273 + 325 + 455 + 525 + 975 + 1365 + 2275 = 7063 14. 7245 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 23 + 35 + 45 + 63 + 69 + 105 + 115 + 161 + 207 + 315 + 345 + 483 + 805 + 1035 + 1449 + 2415 = 7731 15. 7425 < 1 + 3 + 5 + 9 + 11 + 15 + 25 + 27 + 33 + 45 + 55 + 75 + 99 + 135 + 165 + 225 + 275 + 297 + 495 + 675 + 825 + 1485 + 2475 = 7455 16. 7875 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 125 + 175 + 225 + 315 + 375 + 525 + 875 + 1125 + 1575 + 2625 = 8349 17. 8085 < 1 + 3 + 5 + 7 + 11 + 15 + 21 + 33 + 35 + 49 + 55 + 77 + 105 + 147 + 165 + 231 + 245 + 385 + 539 + 735 + 1155 + 1617 + 2695 = 8331 18. 8415 < 1 + 3 + 5 + 9 + 11 + 15 + 17 + 33 + 45 + 51 + 55 + 85 + 99 + 153 + 165 + 187 + 255 + 495 + 561 + 765 + 935 + 1683 + 2805 = 8433 19. 8505 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 81 + 105 + 135 + 189 + 243 + 315 + 405 + 567 + 945 + 1215 + 1701 + 2835 = 8967 20. 8925 < 1 + 3 + 5 + 7 + 15 + 17 + 21 + 25 + 35 + 51 + 75 + 85 + 105 + 119 + 175 + 255 + 357 + 425 + 525 + 595 + 1275 + 1785 + 2975 = 8931 21. 9135 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 29 + 35 + 45 + 63 + 87 + 105 + 145 + 203 + 261 + 315 + 435 + 609 + 1015 + 1305 + 1827 + 3045 = 9585 22. 9555 < 1 + 3 + 5 + 7 + 13 + 15 + 21 + 35 + 39 + 49 + 65 + 91 + 105 + 147 + 195 + 245 + 273 + 455 + 637 + 735 + 1365 + 1911 + 3185 = 9597 23. 9765 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 31 + 35 + 45 + 63 + 93 + 105 + 155 + 217 + 279 + 315 + 465 + 651 + 1085 + 1395 + 1953 + 3255 = 10203 24. 10395 < 1 + 3 + 5 + 7 + 9 + 11 + 15 + 21 + 27 + 33 + 35 + 45 + 55 + 63 + 77 + 99 + 105 + 135 + 165 + 189 + 231 + 297 + 315 + 385 + 495 + 693 + 945 + 1155 + 1485 + 2079 + 3465 = 12645 25. 11025 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 49 + 63 + 75 + 105 + 147 + 175 + 225 + 245 + 315 + 441 + 525 + 735 + 1225 + 1575 + 2205 + 3675 = 11946 The one thousandth abundant odd number is: 492975 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 175 + 225 + 313 + 315 + 525 + 939 + 1565 + 1575 + 2191 + 2817 + 4695 + 6573 + 7825 + 10955 + 14085 + 19719 + 23475 + 32865 + 54775 + 70425 + 98595 + 164325 = 519361 The first abundant odd number above one billion is: 1000000575 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 49 + 63 + 75 + 105 + 147 + 175 + 225 + 245 + 315 + 441 + 525 + 735 + 1225 + 1575 + 2205 + 3675 + 11025 + 90703 + 272109 + 453515 + 634921 + 816327 + 1360545 + 1904763 + 2267575 + 3174605 + 4081635 + 4444447 + 5714289 + 6802725 + 9523815 + 13333341 + 15873025 + 20408175 + 22222235 + 28571445 + 40000023 + 47619075 + 66666705 + 111111175 + 142857225 + 200000115 + 333333525 = 1083561009
J
NB. https://www.math.upenn.edu/~deturck/m170/wk3/lecture/sumdiv.html s=: ([: */ [: ((<:@:(^ >:)/) % <:@:{.) __&q:)&> assert 6045 -: s 1800 aliquot_sum=: -~ s abundant=: < aliquot_sum Filter=: (#~`)(`:6) A=: abundant Filter 1 2 p. i. 260000 NB. a batch of abundant odd numbers # A NB. more than 1000, it's enough. 1054 NB. the first odd abundant numbers (,: aliquot_sum) 26 {. A 945 1575 2205 2835 3465 4095 4725 5355 5775 5985 6435 6615 6825 7245 7425 7875 8085 8415 8505 8925 9135 9555 9765 10395 11025 11655 975 1649 2241 2973 4023 4641 5195 5877 6129 6495 6669 7065 7063 7731 7455 8349 8331 8433 8967 8931 9585 9597 10203 12645 11946 12057 NB. the one thousandth abundant odd number (,: aliquot_sum) 999 { A 492975 519361 k=: adverb def '1000 * m' 1x k k k 1000000000 abundant Filter (1x k k k) + 1 2x p. i. 10x k 1000000575 1000001475 1000001625 1000001835 1000002465 1000003095 1000003725 1000004355 1000004775 1000004985 1000005435 1000005615 1000005825 1000006245 1000006425 1000006875 1000007505 1000008765 1000009395 1000010025 1000010655 1000011285 1000011705 100... (,: aliquot_sum) {. abundant Filter (1x k k k) + 1 2x p. i. 10x k 1000000575 1083561009
Julia
<lang julia>using Primes
function factorsof(n)
f = [one(n)] for (p, x) in factor(n) f = reduce(vcat, [f*p^i for i in 1:x], init=f) end pop!(f) f
end
isabundant(n) = sum(factorsof(n)) > n prettyprintfactors(n) = (a = factorsof(n); println("$n has proper divisors $a, these sum to $(sum(a))."))
function oddabundantsfrom(startingint, needed, nprint=0, targetf=(x -> false))
n = isodd(startingint) ? startingint : startingint + 1 count = 0 while count < needed if isabundant(n) if nprint == 0 prettyprintfactors(n) end if targetf(n) || nprint == count + 1 prettyprintfactors(n) break end count += 1 end n += 2 end
end
println("First 25 abundant odd numbers:") oddabundantsfrom(2, 25)
println("The thousandth abundant odd number:") oddabundantsfrom(2, 1001, 1000)
println("The first abundant odd number greater than one billion:") oddabundantsfrom(2, 1000000000000, -1, x -> x > 1000000000)
</lang>
- Output:
First 25 abundant odd numbers: 945 has proper divisors [1, 3, 9, 27, 5, 15, 45, 135, 7, 21, 63, 189, 35, 105, 315], these sum to 975. 1575 has proper divisors [1, 3, 9, 5, 15, 45, 25, 75, 225, 7, 21, 63, 35, 105, 315, 175, 525], these sum to 1649. 2205 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 49, 147, 441, 245, 735], these sum to 2241. 2835 has proper divisors [1, 3, 9, 27, 81, 5, 15, 45, 135, 405, 7, 21, 63, 189, 567, 35, 105, 315, 945], these sum to 2973. 3465 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 11, 33, 99, 55, 165, 495, 77, 231, 693, 385, 1155], these sum to 4023. 4095 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 13, 39, 117, 65, 195, 585, 91, 273, 819, 455, 1365], these sum to 4641. 4725 has proper divisors [1, 3, 9, 27, 5, 15, 45, 135, 25, 75, 225, 675, 7, 21, 63, 189, 35, 105, 315, 945, 175, 525, 1575], these sum to 5195. 5355 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 17, 51, 153, 85, 255, 765, 119, 357, 1071, 595, 1785], these sum to 5877. 5775 has proper divisors [1, 3, 5, 15, 25, 75, 7, 21, 35, 105, 175, 525, 11, 33, 55, 165, 275, 825, 77, 231, 385, 1155, 1925], these sum to 6129. 5985 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 19, 57, 171, 95, 285, 855, 133, 399, 1197, 665, 1995], these sum to 6495. 6435 has proper divisors [1, 3, 9, 5, 15, 45, 11, 33, 99, 55, 165, 495, 13, 39, 117, 65, 195, 585, 143, 429, 1287, 715, 2145], these sum to 6669. 6615 has proper divisors [1, 3, 9, 27, 5, 15, 45, 135, 7, 21, 63, 189, 35, 105, 315, 945, 49, 147, 441, 1323, 245, 735, 2205], these sum to 7065. 6825 has proper divisors [1, 3, 5, 15, 25, 75, 7, 21, 35, 105, 175, 525, 13, 39, 65, 195, 325, 975, 91, 273, 455, 1365, 2275], these sum to 7063. 7245 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 23, 69, 207, 115, 345, 1035, 161, 483, 1449, 805, 2415], these sum to 7731. 7425 has proper divisors [1, 3, 9, 27, 5, 15, 45, 135, 25, 75, 225, 675, 11, 33, 99, 297, 55, 165, 495, 1485, 275, 825, 2475], these sum to 7455. 7875 has proper divisors [1, 3, 9, 5, 15, 45, 25, 75, 225, 125, 375, 1125, 7, 21, 63, 35, 105, 315, 175, 525, 1575, 875, 2625], these sum to 8349. 8085 has proper divisors [1, 3, 5, 15, 7, 21, 35, 105, 49, 147, 245, 735, 11, 33, 55, 165, 77, 231, 385, 1155, 539, 1617, 2695], these sum to 8331. 8415 has proper divisors [1, 3, 9, 5, 15, 45, 11, 33, 99, 55, 165, 495, 17, 51, 153, 85, 255, 765, 187, 561, 1683, 935, 2805], these sum to 8433. 8505 has proper divisors [1, 3, 9, 27, 81, 243, 5, 15, 45, 135, 405, 1215, 7, 21, 63, 189, 567, 1701, 35, 105, 315, 945, 2835], these sum to 8967. 8925 has proper divisors [1, 3, 5, 15, 25, 75, 7, 21, 35, 105, 175, 525, 17, 51, 85, 255, 425, 1275, 119, 357, 595, 1785, 2975], these sum to 8931. 9135 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 29, 87, 261, 145, 435, 1305, 203, 609, 1827, 1015, 3045], these sum to 9585. 9555 has proper divisors [1, 3, 5, 15, 7, 21, 35, 105, 49, 147, 245, 735, 13, 39, 65, 195, 91, 273, 455, 1365, 637, 1911, 3185], these sum to 9597. 9765 has proper divisors [1, 3, 9, 5, 15, 45, 7, 21, 63, 35, 105, 315, 31, 93, 279, 155, 465, 1395, 217, 651, 1953, 1085, 3255], these sum to 10203. 10395 has proper divisors [1, 3, 9, 27, 5, 15, 45, 135, 7, 21, 63, 189, 35, 105, 315, 945, 11, 33, 99, 297, 55, 165, 495, 1485, 77, 231, 693, 2079, 385, 1155, 3465], these sum to 12645. 11025 has proper divisors [1, 3, 9, 5, 15, 45, 25, 75, 225, 7, 21, 63, 35, 105, 315, 175, 525, 1575, 49, 147, 441, 245, 735, 2205, 1225, 3675], these sum to 11946. The thousandth abundant odd number: 492975 has proper divisors [1, 3, 9, 5, 15, 45, 25, 75, 225, 7, 21, 63, 35, 105, 315, 175, 525, 1575, 313, 939, 2817, 1565, 4695, 14085, 7825, 23475, 70425, 2191, 6573, 19719, 10955, 32865, 98595, 54775, 164325], these sum to 519361. The first abundant odd number greater than one billion: 1000000575 has proper divisors [1, 3, 9, 5, 15, 45, 25, 75, 225, 7, 21, 63, 35, 105, 315, 175, 525, 1575, 49, 147, 441, 245, 735, 2205, 1225, 3675, 11025, 90703, 272109, 816327, 453515, 1360545, 4081635, 2267575, 6802725, 20408175, 634921, 1904763, 5714289, 3174605, 9523815, 28571445, 15873025, 47619075, 142857225, 4444447, 13333341, 40000023, 22222235, 66666705, 200000115, 111111175, 333333525], these sum to 1083561009.
Perl
<lang perl>use strict; use warnings; use feature 'say'; use ntheory qw/divisor_sum divisors/;
sub odd_abundants {
my($start,$count) = @_; my $n = int(( $start + 2 ) / 3); $n += 1 if 0 == $n / 2; $n *= 3; my @out; while (@out < $count) { $n += 6; next unless (my $ds = divisor_sum($n)) > 2*$n; my @d = divisors($n); push @out, sprintf "%6d: divisor sum: %s = %d", $n, join(' + ', @d[0..@d-2]), $ds-$n; } @out;
}
say 'First 25 abundant odd numbers:'; say for odd_abundants(1, 25); say "\nOne thousandth abundant odd number:\n", (odd_abundants(1, 1000))[999]; say "\nFirst abundant odd number above one billion:\n", odd_abundants(999_999_999, 1);</lang>
- Output:
First 25 abundant odd numbers: 945: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 105 + 135 + 189 + 315 = 975 1575: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 175 + 225 + 315 + 525 = 1649 2205: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 35 + 45 + 49 + 63 + 105 + 147 + 245 + 315 + 441 + 735 = 2241 2835: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 81 + 105 + 135 + 189 + 315 + 405 + 567 + 945 = 2973 3465: divisor sum: 1 + 3 + 5 + 7 + 9 + 11 + 15 + 21 + 33 + 35 + 45 + 55 + 63 + 77 + 99 + 105 + 165 + 231 + 315 + 385 + 495 + 693 + 1155 = 4023 4095: divisor sum: 1 + 3 + 5 + 7 + 9 + 13 + 15 + 21 + 35 + 39 + 45 + 63 + 65 + 91 + 105 + 117 + 195 + 273 + 315 + 455 + 585 + 819 + 1365 = 4641 4725: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 27 + 35 + 45 + 63 + 75 + 105 + 135 + 175 + 189 + 225 + 315 + 525 + 675 + 945 + 1575 = 5195 5355: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 17 + 21 + 35 + 45 + 51 + 63 + 85 + 105 + 119 + 153 + 255 + 315 + 357 + 595 + 765 + 1071 + 1785 = 5877 5775: divisor sum: 1 + 3 + 5 + 7 + 11 + 15 + 21 + 25 + 33 + 35 + 55 + 75 + 77 + 105 + 165 + 175 + 231 + 275 + 385 + 525 + 825 + 1155 + 1925 = 6129 5985: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 19 + 21 + 35 + 45 + 57 + 63 + 95 + 105 + 133 + 171 + 285 + 315 + 399 + 665 + 855 + 1197 + 1995 = 6495 6435: divisor sum: 1 + 3 + 5 + 9 + 11 + 13 + 15 + 33 + 39 + 45 + 55 + 65 + 99 + 117 + 143 + 165 + 195 + 429 + 495 + 585 + 715 + 1287 + 2145 = 6669 6615: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 49 + 63 + 105 + 135 + 147 + 189 + 245 + 315 + 441 + 735 + 945 + 1323 + 2205 = 7065 6825: divisor sum: 1 + 3 + 5 + 7 + 13 + 15 + 21 + 25 + 35 + 39 + 65 + 75 + 91 + 105 + 175 + 195 + 273 + 325 + 455 + 525 + 975 + 1365 + 2275 = 7063 7245: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 23 + 35 + 45 + 63 + 69 + 105 + 115 + 161 + 207 + 315 + 345 + 483 + 805 + 1035 + 1449 + 2415 = 7731 7425: divisor sum: 1 + 3 + 5 + 9 + 11 + 15 + 25 + 27 + 33 + 45 + 55 + 75 + 99 + 135 + 165 + 225 + 275 + 297 + 495 + 675 + 825 + 1485 + 2475 = 7455 7875: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 125 + 175 + 225 + 315 + 375 + 525 + 875 + 1125 + 1575 + 2625 = 8349 8085: divisor sum: 1 + 3 + 5 + 7 + 11 + 15 + 21 + 33 + 35 + 49 + 55 + 77 + 105 + 147 + 165 + 231 + 245 + 385 + 539 + 735 + 1155 + 1617 + 2695 = 8331 8415: divisor sum: 1 + 3 + 5 + 9 + 11 + 15 + 17 + 33 + 45 + 51 + 55 + 85 + 99 + 153 + 165 + 187 + 255 + 495 + 561 + 765 + 935 + 1683 + 2805 = 8433 8505: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 81 + 105 + 135 + 189 + 243 + 315 + 405 + 567 + 945 + 1215 + 1701 + 2835 = 8967 8925: divisor sum: 1 + 3 + 5 + 7 + 15 + 17 + 21 + 25 + 35 + 51 + 75 + 85 + 105 + 119 + 175 + 255 + 357 + 425 + 525 + 595 + 1275 + 1785 + 2975 = 8931 9135: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 29 + 35 + 45 + 63 + 87 + 105 + 145 + 203 + 261 + 315 + 435 + 609 + 1015 + 1305 + 1827 + 3045 = 9585 9555: divisor sum: 1 + 3 + 5 + 7 + 13 + 15 + 21 + 35 + 39 + 49 + 65 + 91 + 105 + 147 + 195 + 245 + 273 + 455 + 637 + 735 + 1365 + 1911 + 3185 = 9597 9765: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 31 + 35 + 45 + 63 + 93 + 105 + 155 + 217 + 279 + 315 + 465 + 651 + 1085 + 1395 + 1953 + 3255 = 10203 10395: divisor sum: 1 + 3 + 5 + 7 + 9 + 11 + 15 + 21 + 27 + 33 + 35 + 45 + 55 + 63 + 77 + 99 + 105 + 135 + 165 + 189 + 231 + 297 + 315 + 385 + 495 + 693 + 945 + 1155 + 1485 + 2079 + 3465 = 12645 11025: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 49 + 63 + 75 + 105 + 147 + 175 + 225 + 245 + 315 + 441 + 525 + 735 + 1225 + 1575 + 2205 + 3675 = 11946 One thousandth abundant odd number: 492975: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 175 + 225 + 313 + 315 + 525 + 939 + 1565 + 1575 + 2191 + 2817 + 4695 + 6573 + 7825 + 10955 + 14085 + 19719 + 23475 + 32865 + 54775 + 70425 + 98595 + 164325 = 519361 First abundant odd number above one billion: 1000000575: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 49 + 63 + 75 + 105 + 147 + 175 + 225 + 245 + 315 + 441 + 525 + 735 + 1225 + 1575 + 2205 + 3675 + 11025 + 90703 + 272109 + 453515 + 634921 + 816327 + 1360545 + 1904763 + 2267575 + 3174605 + 4081635 + 4444447 + 5714289 + 6802725 + 9523815 + 13333341 + 15873025 + 20408175 + 22222235 + 28571445 + 40000023 + 47619075 + 66666705 + 111111175 + 142857225 + 200000115 + 333333525 = 1083561009
Perl 6
<lang perl6>sub odd-abundant (\x) {
my @l = x.is-prime ?? 1 !! flat 1, (3 .. x.sqrt.floor).map: -> \d { next unless d +& 1; my \y = x div d; next if y * d !== x; d !== y ?? (d, y) !! d }; @l.sum > x ?? @l.sort !! Empty;
}
sub odd-abundants (Int :$start-at is copy) {
$start-at = ( $start-at + 2 ) div 3; $start-at += $start-at %% 2; $start-at *= 3; ($start-at, *+6 ... *).hyper.map: { next unless my $oa = .&odd-abundant; sprintf "%6d: divisor sum: {$oa.join: ' + '} = {$oa.sum}", $_ }
}
put 'First 25 abundant odd numbers:'; .put for odd-abundants( :start-at(1) )[^25];
put "\nOne thousandth abundant odd number:\n" ~ odd-abundants( :start-at(1) )[999] ~
"\n\nFirst abundant odd number above one billion:\n" ~ odd-abundants( :start-at(1_000_000_000) ).head;</lang>
- Output:
First 25 abundant odd numbers: 945: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 105 + 135 + 189 + 315 = 975 1575: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 175 + 225 + 315 + 525 = 1649 2205: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 35 + 45 + 49 + 63 + 105 + 147 + 245 + 315 + 441 + 735 = 2241 2835: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 81 + 105 + 135 + 189 + 315 + 405 + 567 + 945 = 2973 3465: divisor sum: 1 + 3 + 5 + 7 + 9 + 11 + 15 + 21 + 33 + 35 + 45 + 55 + 63 + 77 + 99 + 105 + 165 + 231 + 315 + 385 + 495 + 693 + 1155 = 4023 4095: divisor sum: 1 + 3 + 5 + 7 + 9 + 13 + 15 + 21 + 35 + 39 + 45 + 63 + 65 + 91 + 105 + 117 + 195 + 273 + 315 + 455 + 585 + 819 + 1365 = 4641 4725: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 27 + 35 + 45 + 63 + 75 + 105 + 135 + 175 + 189 + 225 + 315 + 525 + 675 + 945 + 1575 = 5195 5355: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 17 + 21 + 35 + 45 + 51 + 63 + 85 + 105 + 119 + 153 + 255 + 315 + 357 + 595 + 765 + 1071 + 1785 = 5877 5775: divisor sum: 1 + 3 + 5 + 7 + 11 + 15 + 21 + 25 + 33 + 35 + 55 + 75 + 77 + 105 + 165 + 175 + 231 + 275 + 385 + 525 + 825 + 1155 + 1925 = 6129 5985: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 19 + 21 + 35 + 45 + 57 + 63 + 95 + 105 + 133 + 171 + 285 + 315 + 399 + 665 + 855 + 1197 + 1995 = 6495 6435: divisor sum: 1 + 3 + 5 + 9 + 11 + 13 + 15 + 33 + 39 + 45 + 55 + 65 + 99 + 117 + 143 + 165 + 195 + 429 + 495 + 585 + 715 + 1287 + 2145 = 6669 6615: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 49 + 63 + 105 + 135 + 147 + 189 + 245 + 315 + 441 + 735 + 945 + 1323 + 2205 = 7065 6825: divisor sum: 1 + 3 + 5 + 7 + 13 + 15 + 21 + 25 + 35 + 39 + 65 + 75 + 91 + 105 + 175 + 195 + 273 + 325 + 455 + 525 + 975 + 1365 + 2275 = 7063 7245: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 23 + 35 + 45 + 63 + 69 + 105 + 115 + 161 + 207 + 315 + 345 + 483 + 805 + 1035 + 1449 + 2415 = 7731 7425: divisor sum: 1 + 3 + 5 + 9 + 11 + 15 + 25 + 27 + 33 + 45 + 55 + 75 + 99 + 135 + 165 + 225 + 275 + 297 + 495 + 675 + 825 + 1485 + 2475 = 7455 7875: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 125 + 175 + 225 + 315 + 375 + 525 + 875 + 1125 + 1575 + 2625 = 8349 8085: divisor sum: 1 + 3 + 5 + 7 + 11 + 15 + 21 + 33 + 35 + 49 + 55 + 77 + 105 + 147 + 165 + 231 + 245 + 385 + 539 + 735 + 1155 + 1617 + 2695 = 8331 8415: divisor sum: 1 + 3 + 5 + 9 + 11 + 15 + 17 + 33 + 45 + 51 + 55 + 85 + 99 + 153 + 165 + 187 + 255 + 495 + 561 + 765 + 935 + 1683 + 2805 = 8433 8505: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 27 + 35 + 45 + 63 + 81 + 105 + 135 + 189 + 243 + 315 + 405 + 567 + 945 + 1215 + 1701 + 2835 = 8967 8925: divisor sum: 1 + 3 + 5 + 7 + 15 + 17 + 21 + 25 + 35 + 51 + 75 + 85 + 105 + 119 + 175 + 255 + 357 + 425 + 525 + 595 + 1275 + 1785 + 2975 = 8931 9135: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 29 + 35 + 45 + 63 + 87 + 105 + 145 + 203 + 261 + 315 + 435 + 609 + 1015 + 1305 + 1827 + 3045 = 9585 9555: divisor sum: 1 + 3 + 5 + 7 + 13 + 15 + 21 + 35 + 39 + 49 + 65 + 91 + 105 + 147 + 195 + 245 + 273 + 455 + 637 + 735 + 1365 + 1911 + 3185 = 9597 9765: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 31 + 35 + 45 + 63 + 93 + 105 + 155 + 217 + 279 + 315 + 465 + 651 + 1085 + 1395 + 1953 + 3255 = 10203 10395: divisor sum: 1 + 3 + 5 + 7 + 9 + 11 + 15 + 21 + 27 + 33 + 35 + 45 + 55 + 63 + 77 + 99 + 105 + 135 + 165 + 189 + 231 + 297 + 315 + 385 + 495 + 693 + 945 + 1155 + 1485 + 2079 + 3465 = 12645 11025: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 49 + 63 + 75 + 105 + 147 + 175 + 225 + 245 + 315 + 441 + 525 + 735 + 1225 + 1575 + 2205 + 3675 = 11946 One thousandth abundant odd number: 492975: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 63 + 75 + 105 + 175 + 225 + 313 + 315 + 525 + 939 + 1565 + 1575 + 2191 + 2817 + 4695 + 6573 + 7825 + 10955 + 14085 + 19719 + 23475 + 32865 + 54775 + 70425 + 98595 + 164325 = 519361 First abundant odd number above one billion: 1000000575: divisor sum: 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 49 + 63 + 75 + 105 + 147 + 175 + 225 + 245 + 315 + 441 + 525 + 735 + 1225 + 1575 + 2205 + 3675 + 11025 + 90703 + 272109 + 453515 + 634921 + 816327 + 1360545 + 1904763 + 2267575 + 3174605 + 4081635 + 4444447 + 5714289 + 6802725 + 9523815 + 13333341 + 15873025 + 20408175 + 22222235 + 28571445 + 40000023 + 47619075 + 66666705 + 111111175 + 142857225 + 200000115 + 333333525 = 1083561009
REXX
<lang rexx>/*REXX pgm displays abundant odd numbers: 1st 25, one─thousandth, first > 1 billion. */ parse arg Nlow Nuno Novr . /*obtain optional arguments from the CL*/ if Nlow== | Nlow=="," then Nlow= 25 /*Not specified? Then use the default.*/ if Nuno== | Nuno=="," then Nuno= 1000 /* " " " " " " */ if Novr== | Novr=="," then Novr= 1000000000 /* " " " " " " */ numeric digits max(9, length(Novr) ) /*ensure enough decimal digits for // */ @= 'odd abundant number' /*variable for annotating the output. */
- = 0 /*count of odd abundant numbers so far.*/
do j=3 by 2 until #>=Nlow; $= sigO(j) /*get the sigma for an odd integer. */ if $<=j then iterate /*sigma ≤ J ? Then ignore it. */ #= # + 1 /*bump the counter for abundant odd #'s*/ say th(#) @ 'is: ' commas(j) right('sigma=',20) commas($) end /*j*/
say
- = 0 /*count of odd abundant numbers so far.*/
do j=3 by 2; $= sigO(j) /*get the sigma for an odd integer. */ if $<=j then iterate /*sigma ≤ J ? Then ignore it. */ #= # + 1 /*bump the counter for abundant odd #'s*/ if #<Nuno then iterate /*Odd abundant# count<Nuno? Then skip.*/ say th(#) @ 'is: ' commas(j) right('sigma=',20) commas($) leave end /*j*/
say
do j=1+Novr%2*2 by 2; $= sigO(j) /*get sigma for an odd integer > Novr. */ if $<=j then iterate /*sigma ≤ J ? Then ignore it. */ say th(1) @ 'over' commas(Novr) "is: " commas(j) right('sigma=',20) commas($) leave end /*j*/
exit /*stick a fork in it, we're all done. */ /*──────────────────────────────────────────────────────────────────────────────────────*/ commas:parse arg _; do c_=length(_)-3 to 1 by -3; _=insert(',', _, c_); end; return _ th: parse arg th; return th||word('th st nd rd',1+(th//10)*(th//100%10\==1)*(th//10<4)) /*──────────────────────────────────────────────────────────────────────────────────────*/ sigO: procedure; parse arg x; s= 1 /*sigma for odd integers. ___*/
do k=3 by 2 while k*k<x /*divide by all odd integers up to √ x */ if x//k==0 then s= s + k + x%k /*add the two divisors to (sigma) sum. */ end /*k*/ /* ___*/ if k*k==x then return s + k /*Was X a square? If so, add √ x */ return s /*return (sigma) sum of the divisors. */</lang>
- output when using the default input:
1st odd abundant number is: 945 sigma= 975 2nd odd abundant number is: 1,575 sigma= 1,649 3rd odd abundant number is: 2,205 sigma= 2,241 4th odd abundant number is: 2,835 sigma= 2,973 5th odd abundant number is: 3,465 sigma= 4,023 6th odd abundant number is: 4,095 sigma= 4,641 7th odd abundant number is: 4,725 sigma= 5,195 8th odd abundant number is: 5,355 sigma= 5,877 9th odd abundant number is: 5,775 sigma= 6,129 10th odd abundant number is: 5,985 sigma= 6,495 11th odd abundant number is: 6,435 sigma= 6,669 12th odd abundant number is: 6,615 sigma= 7,065 13th odd abundant number is: 6,825 sigma= 7,063 14th odd abundant number is: 7,245 sigma= 7,731 15th odd abundant number is: 7,425 sigma= 7,455 16th odd abundant number is: 7,875 sigma= 8,349 17th odd abundant number is: 8,085 sigma= 8,331 18th odd abundant number is: 8,415 sigma= 8,433 19th odd abundant number is: 8,505 sigma= 8,967 20th odd abundant number is: 8,925 sigma= 8,931 21st odd abundant number is: 9,135 sigma= 9,585 22nd odd abundant number is: 9,555 sigma= 9,597 23rd odd abundant number is: 9,765 sigma= 10,203 24th odd abundant number is: 10,395 sigma= 12,645 25th odd abundant number is: 11,025 sigma= 11,946 1000th odd abundant number is: 492,975 sigma= 519,361 1st odd abundant number over 1,000,000,000 is: 1,000,000,575 sigma= 1,083,561,009
Ring
<lang ring>
- Project: Nice numbers
max = 25 nr = 0 m = 1 check = 0 index = 0 while true
nice(m) if check = 1 nr = nr + 1 ok if nr = max exit ok m = m + 1
end
func nice(n)
check = 0 nArray = [] for i = 1 to n - 1 if n % i = 0 add(nArray,i) ok next sum = 0 for p = 1 to len(nArray) sum = sum + nArray[p] next if sum > n check = 1 index = index + 1 showArray(n,nArray,sum,index) ok
func showArray(n,nArray,sum,index)
see string(index) + ". " + string(n) + " => " for m = 1 to len(nArray) if m < len(nArray) see string(nArray[m]) + " + " else see string(nArray[m]) + " = " + string(sum) + " > " + string(n) + nl ok next
</lang>
- Output:
1. 12 => 1 + 2 + 3 + 4 + 6 = 16 > 12 2. 18 => 1 + 2 + 3 + 6 + 9 = 21 > 18 3. 20 => 1 + 2 + 4 + 5 + 10 = 22 > 20 4. 24 => 1 + 2 + 3 + 4 + 6 + 8 + 12 = 36 > 24 5. 30 => 1 + 2 + 3 + 5 + 6 + 10 + 15 = 42 > 30 6. 36 => 1 + 2 + 3 + 4 + 6 + 9 + 12 + 18 = 55 > 36 7. 40 => 1 + 2 + 4 + 5 + 8 + 10 + 20 = 50 > 40 8. 42 => 1 + 2 + 3 + 6 + 7 + 14 + 21 = 54 > 42 9. 48 => 1 + 2 + 3 + 4 + 6 + 8 + 12 + 16 + 24 = 76 > 48 10. 54 => 1 + 2 + 3 + 6 + 9 + 18 + 27 = 66 > 54 11. 56 => 1 + 2 + 4 + 7 + 8 + 14 + 28 = 64 > 56 12. 60 => 1 + 2 + 3 + 4 + 5 + 6 + 10 + 12 + 15 + 20 + 30 = 108 > 60 13. 66 => 1 + 2 + 3 + 6 + 11 + 22 + 33 = 78 > 66 14. 70 => 1 + 2 + 5 + 7 + 10 + 14 + 35 = 74 > 70 15. 72 => 1 + 2 + 3 + 4 + 6 + 8 + 9 + 12 + 18 + 24 + 36 = 123 > 72 16. 78 => 1 + 2 + 3 + 6 + 13 + 26 + 39 = 90 > 78 17. 80 => 1 + 2 + 4 + 5 + 8 + 10 + 16 + 20 + 40 = 106 > 80 18. 84 => 1 + 2 + 3 + 4 + 6 + 7 + 12 + 14 + 21 + 28 + 42 = 140 > 84 19. 88 => 1 + 2 + 4 + 8 + 11 + 22 + 44 = 92 > 88 20. 90 => 1 + 2 + 3 + 5 + 6 + 9 + 10 + 15 + 18 + 30 + 45 = 144 > 90 21. 96 => 1 + 2 + 3 + 4 + 6 + 8 + 12 + 16 + 24 + 32 + 48 = 156 > 96 22. 100 => 1 + 2 + 4 + 5 + 10 + 20 + 25 + 50 = 117 > 100 23. 102 => 1 + 2 + 3 + 6 + 17 + 34 + 51 = 114 > 102 24. 104 => 1 + 2 + 4 + 8 + 13 + 26 + 52 = 106 > 104 25. 108 => 1 + 2 + 3 + 4 + 6 + 9 + 12 + 18 + 27 + 36 + 54 = 172 > 108