HW2 Q3 - main thread

Question 3 was renamed in the updated PDF to question 4, and 4 is now 5. It's probably better to fix this to avoid confusion.

I made a mistake in this question to think that 1 is a perfect number.

I was really surprised to see that this mistake cost me **10** points.

you can clearly see that if someone does not understand the question and thinks 1 is perfect, they will trigger these mistakes:

T32_2, T33_x, 3C_1

Was it intended?

Please address the HW checker with an appeal. We may consider giving a few points back in this case, depending on your mistakes.

We are only interested in divisors of n that are not equal to n.

For n=1 there are no such divisors, therefore the sum is 0.

should sum_divisors only sum prime divisors (and thus ony rum up to n^0.5) or does it have to incluse ALL the divisors, like n/2?

My sum_dividors runs only until n**0.5, but still it takes a lot of time (over 3 minutes) to count how many perfect numbers there are until 1,000,000. Is it OK? Are we supposed to find a faster way to do it?

In this question (count_perfect_numbers) we only require a solution in O(sqrt(n)) and without an obvious and substantial waste of time. I suppose that it shouldn't take longer than 3 minutes though. make sure your sum_divisors implementation is efficient enough and also make sure that you see a (significant) reduction in runtime comparing to a naive implementation of sum_divisors.

I will have to rephrase my question.

The count_perfect_number(10**6) runs in ~ 150 seconds average.

Is this acceptable?

(The naive implementation runs in more than 15 minutes…)

We deliberately do not specify running time requirements here.

We leave it for you to ponder whether or not your code includes a substantial inefficiency.

yes, although x**0.5 will also do.

(also note that it is math, not Math)

May I assume that odd numbers smaller than 1 million aren't perfect number?

בשאלה 3 סעיף ג' כתוב בהתחלה: "נרצה לדעת כמה מספרים מושלמים יש שקטנים מ-1,000,000"

אבל בהמשך כתוב שהפונקציה צריכה להחזיר כמה מספרים מושלמים קטנים או שווים ל-limit.

רק רציתי לוודא - האם אנו צריכים לבדוק כמה מספרים יש שקטנים או כמה מספרים יש שקטנים או שווים ל-limit?

תודה רבה.

זה באמת מטעה. **השורה הראשונה היתה צריכה להיות "נרצה לדעת כמה מספרים מושלמים יש שקטנים או שווים ל-1,000,000"**

אתם מתבקשים לכתוב פונקציה שמקבלת מספר limit ומחשבת כמה מספרים מושלמים יש **שקטנים או שווים** ל-limit.

בנוסף עליכם להפעיל פונקציה זו על מנת לחשב כמה מספרים מושלמים יש **שקטנים או שווים** ל 1,000,000.

(1,000,000 עצמו הוא לא מספר מושלם ולכן הטעות בניסוח השאלה לא משפיעה על התשובה הסופית)

I want to edit the previous post: in the function is_perfect I used the following command: from 204..(my id) import sum_divisors

and then the rest of the function..

it didn't work when the name of the program after the from is in numbers, but did work when the name is in letters. we are required to change it to our id so it won't work. should I pay any attention to this? or will it work properly without the from.. import command because all the programs are in the same file so no need to import? thanks

If all the functions are defined in one file then you won't need to use import at all. All the functions you created are "imported" once you run the program (The final file should include all the functions anyways)

3. Gimel: check only positive numbers that are < or = 1000000?

You need to count the number of perfect numbers that are <= 1000000