<p>Given an integer array <code>nums</code>, return <em>the sum of divisors of the integers in that array that have exactly four divisors</em>. If there is no such integer in the array, return <code>0</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [21,4,7]
<strong>Output:</strong> 32
<strong>Explanation:</strong> 
21 has 4 divisors: 1, 3, 7, 21
4 has 3 divisors: 1, 2, 4
7 has 2 divisors: 1, 7
The answer is the sum of divisors of 21 only.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [21,21]
<strong>Output:</strong> 64
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,3,4,5]
<strong>Output:</strong> 0
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
</ul>

class Solution {
public:
    int sumFourDivisors(vector<int>& nums) {
        int sumDivisors = 0;

        for (int currentNum : nums) {
            if (currentNum <= 1) {
                //less than 1 divisor -> not included
                continue;
            }
            vector<int> currentFactors;
            //all numbers > 1 have 1 and number as factor
            int numFactors = 2;

            for (int i = 2; i <= sqrt(currentNum); i++) {
                //check if each number until sqrt is a factor

                if (currentNum % i == 0) {
                    //this number is a factor 
                    int compliment = currentNum / i;

                    if (compliment == i) {
                        //perfect square! -> only one factor
                        numFactors++;
                        currentFactors.push_back(i);
                    }
                    else {
                        //not perfect square -> add both!
                        numFactors += 2;
                        currentFactors.push_back(i);
                        currentFactors.push_back(compliment);
                    }
                    if (numFactors > 4) {
                        break;
                    }
                }
            }
            //found all factors
            if (numFactors == 4) {
                sumDivisors += 1 + currentNum;
                for (int factor : currentFactors) {
                    sumDivisors += factor;
                }
            }
            //repeat same operation for every element in nums
        }
        return sumDivisors;
    }
};
21300