# Sum of all subsets whose sum is a Perfect Number from a given array

Given an array arr[] consisting of N integers, the task is to find the sum of all subsets from an array, whose sum is a Perfect Number.

Examples:

Input: arr[] = {5, 4, 6}Output: 6Explanation:All possible subsets from the array arr[] are:{5} → Sum = 5{4} → Sum = 4.{6} → Sum = 6.{5, 4} → Sum = 9.{5, 6} → Sum = 11.{4, 6} → Sum = 10.{5, 4, 6} → Sum = 15.Out of all subset sums, only 6 sums are found to be2` a perfect number.

Input: arr[] = {28, 6, 23, 3, 3}Output: 28 6 6

Recursive Approach: The idea is to generate all possible subsets from the given array and print the sum of those subsets whose sum is a perfect number.Below is the implementation of the above approach:

C++

#include

using namespace std;

int isPerfect(int x)

{

int sum_div = 1;

for (int i = 2; i r) {

if (isPerfect(sum)) {

cout