By Perfect Number do you mean https://en.wikipedia.org/wiki/Perfect_number ? So the first four are 6, 28, 496, 8128 . This reminds me of some of the questions from the site Project Euler, which had some math-based programming questions, and which I tended to solve in a scripting language like Ruby ;D
1. But anyway, first come up with an algorithm. If indeed this is the kind of perfect number they're looking for, as per the list at http://oeis.org/A000396 , this stuff scales up FAST. Look again what kind of upper ceiling the input could be, which could be the difference of integer (int) or really big numbers (long long)
2. Don't panic; break it up into parts. Looks like it involves prime numbers -- do you have a way of generating a prime number list? Perhaps create a function that generates the first 10000 prime numbers in a vector or so, and then in your Perfect() function, start iterating through them [2,3,5,7...] to generate that 2^(p-1) * (2^p - 1) , which seems valid, until upper limit is reached.
@icy1 thanks for ur reply
Yesss my Question requires e.g. input 100 ouput 6 28
i didnt get the prime number part
Why we need prime number to find the prefect number?
Thank you sooo much
Edit: since for this particular question, the output scales up so fast and you might not anticipate huge input from user, you could simply have a bunch of primes hard-coded and avoid making a prime-generation method. vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19}; Could add a comment explaining the limitations of the input.