0

I was trying to solve the deficient number lesson, but I don't understand why on SoloLearn my code doesn't work for big numbers

It does work on another app, I'm not sure why here for numbers with more than four factors it just says "no input" (is it possible that my internet connection is too slow?) Here's the assignment, I tried the hard task: A number is considered deficient if the sum of its factors is less than twice that number. For Example: 10 is a deficient number. Factors of 10 are 1, 2, 5, 10 Sum is 1 + 2 + 5 + 10 = 18 < 2 * 10 Tasks: (Easy) Write a program to verify whether a given number is deficient or not. (Medium) Write a program to find all the deficient numbers in a range. (Hard) Given a number, write a program to display its factors, their sum and then verify whether it's deficient or not https://code.sololearn.com/cy7aBI7ho0F5/?ref=app

17th Aug 2019, 10:05 AM
Lea
3 Answers
+ 1
your code is fine, SoloLearn only uses 10secs to process your code, any code taking longer time than that will not be executed, and in your case a bigger value will take a long time to process
17th Aug 2019, 11:27 AM
✳AsterisK✳
✳AsterisK✳ - avatar
+ 3
you can make your code faster for example n%i will not be 0 if i >n/2 so the loop should be <n/2 rather than n calloc assigns the memory to 0 you don't have to assign it linkedlist is faster than reallocation in big cases you can count the sum in the same loop at line 38 also you can break the loop and print No when the sum is bigger than n/2
17th Aug 2019, 1:21 PM
ABADA S
ABADA S - avatar
0
Thank you!
17th Aug 2019, 11:56 AM
Lea