In number theory, a semiperfect number or pseudoperfect number is a natural number n that is equal to the sum of all or some of its proper divisors. A semiperfect number that is equal to the sum of all its proper divisors is a perfect number.
Given a number, the task is to check if the number is a semi-perfect number or not.
Output: The number is Semiperfect
Output: The number is not Semiperfect
The first few semiperfect numbers are
6, 12, 18, 20, 24, 28, 30, 36, 40
Approach: Store all th factors of the number in a data-structure(Vector or Arrays). Sort them in increasing order. Once the factors are stored, Dynamic programming can be used to check if any combination forms N or not. The problem becomes similar to the Subset Sum Problem. We can use the same approach and check if the number is a semi-perfect number or not.
Below is the implementation of the above approach.
Time Complexity: O(number of factors * N)
Auxiliary Space: O(number of factors * N)
- Count number of trailing zeros in Binary representation of a number using Bitset
- Super Ugly Number (Number whose prime factors are in given set)
- Number of ways to represent a number as sum of k fibonacci numbers
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Find the maximum number of composite summands of a number
- Find the total number of composite factor for a given number
- Represent a number as a sum of maximum possible number of Prime Numbers
- Program to check whether a number is Proth number or not
- Minimum number of cubes whose sum equals to given number N
- Minimum number of squares whose sum equals to given number n
- Number of ways to get a given sum with n number of m-faced dices
- k-Rough Number or k-Jagged Number
- Number of divisors of a given number N which are divisible by K
- Check whether a number is Non-hypotenuse number
- Check if a number is an Achilles number or not
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.