Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Am I not good enough for you?

Background:

The current Perfect Numbers challenge is rather flawed and complicated, since it asks you to output in a complex format involving the factors of the number. This is a purely repost of the challenge.

Challenge

Given a positive integer through any standard input format, distinguish between whether it is perfect or not.

A perfect number is a number that is equal to the sum of all its proper divisors (its positive divisors less than itself). For example, \6ドル\$ is a perfect number, since its divisors are \1,2,3ドル\$, which sum up to \6ドル\$, while \12ドル\$ is not a perfect number since its divisors ( \1,2,3,4,6ドル\$ ) sum up to \16ドル\$, not \12ドル\$.

Test Cases:

Imperfect:
1,12,13,18,20,1000,33550335
Perfect:
6,28,496,8128,33550336,8589869056

Rules

  • Your program doesn't have to complete the larger test cases, if there's memory or time constraints, but it should be theoretically able to if it were given more memory/time.
  • Output can be two distinct and consistent values through any allowed output format. If it isn't immediately obvious what represents Perfect/Imperfect, please make sure to specify in your answer.

Answer*

Draft saved
Draft discarded
Cancel
5
  • \$\begingroup\$ 22 bytes \$\endgroup\$ Commented Mar 10, 2021 at 22:09
  • \$\begingroup\$ @l4m2 That's a great way to do abundant numbers with full 32-bit input support costing just 2 bytes, but as I know you know, this is perfect numbers :-) \$\endgroup\$ Commented Mar 11, 2021 at 15:14
  • \$\begingroup\$ Hmm didn't go up to check question \$\endgroup\$ Commented Mar 11, 2021 at 17:01
  • \$\begingroup\$ Is there any case where the difference happens to be times of 2^32? \$\endgroup\$ Commented Mar 11, 2021 at 17:01
  • \$\begingroup\$ @l4m2 I checked a couple days ago, generating all aliquot sums up to 2^32-1, and there are none where σ(n) = n + k*2^32. Nevertheless, I didn't want to remove my jc instruction even though it'd save 2 bytes, because I really like having a single routine that handles both abundant and perfect numbers, and also would work with any operand size (not just 32 bits)... but yep, you have a point, technically I could drop 2 bytes this way. But that would be like hard-coding the perfect numbers rather than detecting them. \$\endgroup\$ Commented Mar 11, 2021 at 17:17

AltStyle によって変換されたページ (->オリジナル) /