Jump to content

Abundant odd numbers: Difference between revisions

(Added Perl example)
Line 168:
1000000575
1083561009
</pre>
 
 
=={{header|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>{{out}}
<pre>
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.
</pre>
 
4,105

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.