Presentation is loading. Please wait.

Presentation is loading. Please wait.

軟體實驗 Perfect Number Enumerating 虞台文. Perfect Numbers A perfect number is such that it is equal to the sum of its proper divisors, which are any divisors.

Similar presentations


Presentation on theme: "軟體實驗 Perfect Number Enumerating 虞台文. Perfect Numbers A perfect number is such that it is equal to the sum of its proper divisors, which are any divisors."— Presentation transcript:

1 軟體實驗 Perfect Number Enumerating 虞台文

2 Perfect Numbers A perfect number is such that it is equal to the sum of its proper divisors, which are any divisors less than the number.perfect number Examples: – Proper divisors of 6  1, 2, 3 6  1 + 2 + 3 – Proper divisors of 10  1, 2, 5 10  1 + 2 + 5 – Proper divisors of 28  1, 2, 4, 7, 14 28  1 + 2 + 4 + 7 + 14

3 Perfect Numbers A perfect number is such that it is equal to the sum of its proper divisors, which are any divisors less than the number.perfect number Examples: – Proper divisors of 6  1, 2, 3 6  1 + 2 + 3 – Proper divisors of 10  1, 2, 5 10  1 + 2 + 5 – Proper divisors of 28  1, 2, 4, 7, 14 28  1 + 2 + 4 + 7 + 14  : perfect  : imperfect

4 The Problem Write a program to determine all the perfect numbers between 1 and 99999.

5 Helper Functions int IsPerfect(int n) returns 1 if n is perfect and 0 otherwise. int NextPropDiv(int now, int n) now  the current proper divisor of n returns the next proper divisor if it exists, and 0 otherwise.

6 The Problem A perfect number is such that it is equal to the sum of its proper divisors, which are any divisors less than the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3, and 28 is another perfect number because 28 = 1 + 2 + 4 + 7 + 14. Write a program to determine all the perfect numbers between 1 and 99999. Your program should include functions int IsPerfect(int n) and int NextPropDiv(int now, int n). Function IsPerfect takes an integer n and returns 1 if n is perfect and 0 otherwise. Function NextPropDiv takes two integers now and n, now denoting the current proper divisor of n, and returns the next proper divisor if it exists, and 0 if it does not. A perfect number is such that it is equal to the sum of its proper divisors, which are any divisors less than the number. For example, 6 is a perfect number because 6 = 1 + 2 + 3, and 28 is another perfect number because 28 = 1 + 2 + 4 + 7 + 14. Write a program to determine all the perfect numbers between 1 and 99999. Your program should include functions int IsPerfect(int n) and int NextPropDiv(int now, int n). Function IsPerfect takes an integer n and returns 1 if n is perfect and 0 otherwise. Function NextPropDiv takes two integers now and n, now denoting the current proper divisor of n, and returns the next proper divisor if it exists, and 0 if it does not.


Download ppt "軟體實驗 Perfect Number Enumerating 虞台文. Perfect Numbers A perfect number is such that it is equal to the sum of its proper divisors, which are any divisors."

Similar presentations


Ads by Google