+ 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 :)

21st Aug 2017, 11:19 PM
Luca
Luca - avatar
227 Answers
+ 139
I think you will enjoy this one :) https://code.sololearn.com/WnT56osg0qMe/#js Very Likable ;)
22nd Aug 2017, 8:58 PM
Louis
Louis - avatar
22nd Aug 2017, 4:07 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 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
23rd Aug 2017, 4:53 AM
ben1z
ben1z - avatar
+ 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
22nd Aug 2017, 3:06 AM
Vari93
Vari93 - avatar
+ 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
22nd Aug 2017, 4:11 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 18
i*2 == sum_divisors (sum_divisors (i)) https://code.sololearn.com/cLkFJoa6Ki9E/?ref=app
22nd Aug 2017, 10:20 AM
hamletmun
hamletmun - avatar
22nd Aug 2017, 3:13 AM
André
André - avatar
+ 13
Congrats for Challenge of the Day :) https://code.sololearn.com/cY3r3eeWxYiR/?ref=app
28th Aug 2017, 6:07 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 12
1+2+4+8=15 15+5+3+1=24 24/2=12
29th Aug 2017, 7:42 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 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
22nd Aug 2017, 4:12 AM
Zephyr Koo
Zephyr Koo - avatar
+ 10
nice tries! for those whose code doesn't output the explanation, try to add it as @Vari93's code does :)
22nd Aug 2017, 4:15 AM
Luca
Luca - avatar
+ 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. 😉
23rd Aug 2017, 11:16 AM
Zephyr Koo
Zephyr Koo - avatar
+ 10
@Nika 8 isn't superperfect, according to your code
29th Aug 2017, 7:40 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 10
In fact, all superperfects should be powers of 2, but not all powers of 2 are superperfect :D
29th Aug 2017, 7:44 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
22nd Aug 2017, 4:55 PM
Mrityunjay Jha
Mrityunjay Jha - avatar
+ 9
https://code.sololearn.com/WtR9f5XX7CUV/?ref=app Its mine ;-)
29th Aug 2017, 4:14 AM
Daniel
Daniel - avatar
29th Aug 2017, 7:48 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 8
https://code.sololearn.com/cC4u2jj376Nw/?ref=app
28th Aug 2017, 4:06 PM
rajeshraj
rajeshraj - avatar
+ 8
I have not seen this challenge before. However, here's my try for my first challenge : https://code.sololearn.com/cRRRbLp3Khw3/?ref=app
28th Aug 2017, 5:20 PM
LukArToDo
LukArToDo - avatar
28th Aug 2017, 7:15 PM
Izmael Kno
Izmael Kno - avatar