14
2
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.
4Is that sequence just the sum of
n
s divisors? You'll probably want to state that explicitly. – Martin Ender – 2017-12-02T18:31:10.7603Also, judging by your "expected output" you want both
n
andf(n)
, but you don't say so anywhere in the specification. – Martin Ender – 2017-12-02T18:32:22.370@MartinEnder Thanks, hopefully its clearer now. – StudleyJr – 2017-12-02T18:38:41.990
IS
f(1,000)
supposed to meanf(1000)
? Is so, please remove the commas as it makes it harder to understand – caird coinheringaahing – 2017-12-02T18:39:51.9872Bonuses are bad, especially when they are vague. I decided to remove it, in order to protect this from being downvoted. – Mr. Xcoder – 2017-12-02T18:42:29.310
2Could you recheck
f(1000) = 48
? The divisor sum of48
is124
– caird coinheringaahing – 2017-12-02T18:49:00.493Oops, everything is multiplied by 10 (my bad), will edit now – StudleyJr – 2017-12-02T18:51:05.747
1Could you update to mention the expected output earlier in the spec. As it's not mentioned until after the test cases, some, like me, may miss it and just output
n
. – Shaggy – 2017-12-02T19:32:08.853Would it be acceptable to include the original value of
x
with our output? – Shaggy – 2017-12-02T19:36:25.9901Can the outputs be in reverse order, i.e.
124,48
? – Zgarb – 2017-12-02T20:38:56.1502Can you check
f(500000)
? I believe the 126000th number in the sequence is 502944. – duckmayr – 2017-12-02T20:54:53.763Same as @duckmayr, I get f(500000) = 126000, 502944. – fede s. – 2017-12-02T22:46:01.803
Ah it should be f(5,000,000), not f(500,000). It's missing a 0. @duckmayr – fede s. – 2017-12-02T22:47:12.863
3It's good to wait at least a week before accepting an answer, otherwise you might discourage new solutions. – Zgarb – 2017-12-03T14:31:12.947