0

A positive integer number n is said to be perfect if it is equal to the sum of its proper
divisors. In other words, n is equal to the sum of its positive divisors excluding itself. For
example, 6 and 28 are perfect numbers. Indeed, we have:
6 = 1 + 2 + 3
28 = 1 + 2 + 4 + 7 + 14
Assume that the input contains a sequence of integers, each of which could be negative,
positive, or equal to zero. Moreover, this sequence ends with the integer –1.
2

1. Write a C++ program that reads a sequence of integers and saves it into an array. Your
program has to check whether each integer n in the sequence is perfect using a brute
force approach. That is, your program should use all possible divisors of n from 2 to n–1.

2. Is it possible to optimize the above C++ program? Explain your answer

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by strmstn
0

That is just an assignment. How far have you gotten? Any thoughts on how to solve the exercise?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.