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*

Proper Divisor mash-up

A proper divisor is a divisor of a number n, which is not n itself. For example, the proper divisors of 12 are 1, 2, 3, 4 and 6.

You will be given an integer x, x ≥ 2, x ≤ 1000. Your task is to sum all the highest proper divisors of the integers from 2 to x (inclusive) (OEIS A280050).

Example (with x = 6):

  • Find all the integers between 2 and 6 (inclusive): 2,3,4,5,6.

  • Get the proper divisors of all of them, and pick the highest ones from each number:

    • 2 -> 1
    • 3 -> 1
    • 4 -> 1, 2
    • 5 -> 1
    • 6 -> 1, 2, 3.
  • Sum the highest proper divisors: 1 +たす 1 +たす 2 +たす 1 +たす 3 = 8.

  • The final result is 8.

Test Cases

Input | Output
-------+---------
 |
 2 | 1
 4 | 4
 6 | 8
 8 | 13
 15 | 41
 37 | 229
 100 | 1690
 1000 | 165279

Rules

Answer*

Draft saved
Draft discarded
Cancel
2
  • \$\begingroup\$ Since f is a pure function, you can memoize it to run the larger cases on TIO \$\endgroup\$ Commented Jun 25, 2017 at 2:55
  • \$\begingroup\$ Right, not being able to use a decorator threw me off. Thanks! \$\endgroup\$ Commented Jun 25, 2017 at 3:06

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