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*

Calculate the lowest number where the sum of the sequence of numbers exceeds a given value

Given you have an infinite sequence of numbers defined as follows:

1: 1 = 1
2: 1 + 2 = 3
3: 1 + 3 = 4
4: 1 + 2 + 4 = 7
5: 1 + 5 = 6
6: 1 +たす 2 +たす 3 +たす 6 = 12
7: 1 + 7 = 8
...

The sequence is the sum of the divisors of n, including 1 and n.

Given a positive integer x as input, calculate the lowest number n which will produce a result greater than x.

Test cases

f(100) = 48, ∑ = 124
f(25000) = 7200, ∑ = 25389
f(5000000) = 1164240, ∑ = 5088960

Expected Output

Your program should return both n and the sum of its divisors, like so:

$ ./challenge 100
48,124

Rules

This is code-golf so the shortest code in bytes, in each language wins.

Answer*

Draft saved
Draft discarded
Cancel
6
  • 1
    \$\begingroup\$ Welcome to the site and nice first post. You can get to 98 bytes by removing the f= as anonymous functions are perfectly acceptable here! \$\endgroup\$ Commented Dec 3, 2017 at 21:59
  • \$\begingroup\$ You can't call an anonymous function from another line of code, is the problem -- I have a separate print(f(100)) statement to test that the function works. \$\endgroup\$ Commented Dec 3, 2017 at 22:02
  • \$\begingroup\$ That's not a problem here. It's perfectly acceptable and works to not include the f= in your byte count, and is a good way to golf in Python. Check this for more golfing tips in Python! \$\endgroup\$ Commented Dec 3, 2017 at 22:05
  • \$\begingroup\$ Hm. I can equal, but not better, my submission by appending q=range and replacing range with q in both existing instances. Sadly, this doesn't improve it and since lambda is a keyword I can't use it for that, I'd have to do exec() tricks wasting too many characters. \$\endgroup\$ Commented Dec 4, 2017 at 15:32
  • \$\begingroup\$ @MichaelBoger Well, you can call an anonymous function in Python; lambda expressions do not have to be assigned to a variable. \$\endgroup\$ Commented Dec 4, 2017 at 16:10

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