43
\$\begingroup\$

An Abundant number is any number where the sum of its proper divisors is greater than the original number. For example, the proper divisors of 12 are:

1, 2, 3, 4, 6

And summing these results in 16. Since 16 is larger than 12, 12 is abundant. Note that this does not include "Perfect numbers", e.g. numbers that are equal to the sum of its proper divisors, such as 6 and 28.

Your task for today is to write a program or function that determines if a number is abundant or not. Your program should take a single integer as input, and output a truthy/falsy value depending on whether it is abundant or not. You can assume that the input will always be valid and greater than 0, so for bad inputs, undefined behavior is fine.

You may take your input and output in any reasonable format, for example STDIN/STDOUT, files, or arguments/return values would all be acceptable.

For reference, here are the abundant numbers up to 100:

12,
18,
20,
24,
30,
36,
40,
42,
48,
54,
56,
60,
66,
70,
72,
78,
80,
84,
88,
90,
96,
100

And more can be found on A005101

Since this is , standard loopholes are denied, and try to write the shortest possible code you can in whichever language you happen to choose!

\$\endgroup\$
3
  • 11
    \$\begingroup\$ "the first odd abundant is 945 = 3^3*5*7, the 232nd abundant number!" \$\endgroup\$ – mbomb007 Feb 21 '17 at 14:29
  • \$\begingroup\$ The asymptotic density of abundant numbers is somewhere within the interval [0.24761748, 0.24764422]. Calculated using the source code included in this paper. \$\endgroup\$ – Deadcode Jan 25 '19 at 22:20
  • 1
    \$\begingroup\$ I am trying to do this in Geometry Dash. It's a nightmare \$\endgroup\$ – MilkyWay90 Jan 29 '19 at 3:25

63 Answers 63

1 2
3
0
\$\begingroup\$

tinylisp, 78 bytes

(load library
(q((N)(l N(sum(filter(partial divides?(q D)(list(q _)N))(range N

Try it online!

Start with a list of each D from 0 through N - 1; filter it for the values of D that exactly divide N. Sum the results. Iff N is less than that sum, N is abundant.

\$\endgroup\$
0
\$\begingroup\$

TI-BASIC, 21 bytes

seq(I,I,1,A-1
A<sum(Ansnot(fpart(A/Ans

TI-BASIC usually has a builtin for this kind of thing, but nothing fits that well here. Takes input from the A variable and outputs 1 or 0 if the number is or isn't abundant.

seq( generates a list of numbers from a function. Here it executes the function I on the I variable from one to one less than the input. Then working backward from the next line, we divide our input by the list we generated (stored in Ans) and take the fractional part so we have a new list of remainders for each potential divisor. We then build a list of booleans by taking not( on the remainder list and multiply that by the original list in Ans implicitly to get a list of proper divisors. Then we just sum the list of proper divisors and compare that to the input.

This was 24 bytes, golfed down to 21 using not( instead of *(0=

\$\endgroup\$
0
\$\begingroup\$

Excel, 46 bytes

=LET(s,SEQUENCE(A3-1),SUM((MOD(A3,s)=0)*s)>A3)

Works for numbers up to 2^20 + 1 (1,048,577).

This 90 byte version works for numbers up to (2^20 + 1) ^ 2 - 1 (1,099,513,724,928).

=LET(s,SEQUENCE(SQRT(A2)),m,(MOD(A2,s)=0)*s,g,IFERROR(A2/m,0),SUM(m,g)-A2-SUM((m=g)*m)>A2)
\$\endgroup\$
1 2
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.