軟體實驗 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 less than the number.perfect number Examples: – Proper divisors of 6 1, 2, 3 6 – Proper divisors of 10 1, 2, 5 10 – Proper divisors of 28 1, 2, 4, 7,
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 – Proper divisors of 10 1, 2, 5 10 – Proper divisors of 28 1, 2, 4, 7, : perfect : imperfect
The Problem Write a program to determine all the perfect numbers between 1 and
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.
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 = , and 28 is another perfect number because 28 = Write a program to determine all the perfect numbers between 1 and 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 = , and 28 is another perfect number because 28 = Write a program to determine all the perfect numbers between 1 and 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.