+ 173
[ASSIGNMENT] superperfect numbers
in mathematics, superperfect numbers are numbers matching the following criteria: sum of dividers of n is d and sum of dividers of d is n*2. to make an example, 4 is a superperfect number, as 4's dividers are 1,2,4. 1+2+4= 7, and 7's dividers are 1,7. notice as 1+7=8 (4*2) in short, 4 => 1+2+4= 7 => 1+7 = 8 = 4*2. task: write a code to find all the superperfect numbers from 1 to x (code should provide explanation) in any language you prefer enjoy coding :)
230 Answers
+ 139
I think you will enjoy this one :)
https://code.sololearn.com/WnT56osg0qMe/#js
Very Likable ;)
+ 55
+ 40
Hello! I just started teaching myself Java a couple of days ago and this is the first challenge I've ever completed. It may look basic but I'm really proud of my solution so I hope you like it!
https://code.sololearn.com/cAJ2XInveFk4/?ref=app
+ 34
Here you go. Checks for valid numerical input and outputs the sum of the original number's divisors, the sum of that sum's divisors, and the original number multiplied by two
https://code.sololearn.com/c7Kj2ax3l2Pi/?ref=app
+ 19
Well Sir Krishna is on rage mode!
Edit: I can't be idle, so here is my highly-inefficient version:
https://code.sololearn.com/cx4S6h06893H/?ref=app
+ 18
i*2 == sum_divisors (sum_divisors (i))
https://code.sololearn.com/cLkFJoa6Ki9E/?ref=app
+ 14
My solution in Ruby:
https://code.sololearn.com/cvfqcuQ1JvQl/?ref=app
+ 13
Congrats for Challenge of the Day :)
https://code.sololearn.com/cY3r3eeWxYiR/?ref=app
+ 12
1+2+4+8=15
15+5+3+1=24
24/2=12
+ 11
Here's my C# implementation ✌
LINQ One-Liner〰
Enumerable
.Range(1, (int)sqrt)
.Where(n => (number % n == 0))
.Sum(n => n + (number / n)) -
(Math.Ceiling(sqrt) == Math.Floor(sqrt) ? (int)sqrt : 0);
Yeah I agree the LINQ looks kinda ugly here and perform quite poor. This is kinda a naive method and I'll try to improve it when got time later. Enjoy!
https://code.sololearn.com/cOw2hsdm0Pvj/?ref=app
+ 10
nice tries! for those whose code doesn't output the explanation, try to add it as @Vari93's code does :)
+ 10
@Mrityunjay you may consider to reduce the number of iteration of your for loop by halve by looping until the square root of the number when finding the factor.
This is because you can compute another pair when you found one of its factor.
For example, f(10) = 1, 2, 5, 10. You can loop until 3 floor(sqrt(10)) as if you know 2 is the factor, then you can determine its pair by dividing 10 with 2.
Anyway take note that every integer have even number of factors except a perfect square. 😉
+ 10
@Nika 8 isn't superperfect, according to your code
+ 10
In fact, all superperfects should be powers of 2, but not all powers of 2 are superperfect :D
+ 9
https://code.sololearn.com/WtR9f5XX7CUV/?ref=app
Its mine ;-)
+ 9
Here we go, another one
https://code.sololearn.com/c7Nc4Fh31Ryw/?ref=app
+ 8
https://code.sololearn.com/cC4u2jj376Nw/?ref=app
+ 8
I have not seen this challenge before.
However, here's my try for my first challenge :
https://code.sololearn.com/cRRRbLp3Khw3/?ref=app
+ 8
my code is.....
https://code.sololearn.com/cxiVyrCzt5at/?ref=app