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

&nbsp;
Example 1:

Input: nums = [21,4,7]
Output: 32
Explanation: 
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.


Example 2:

Input: nums = [21,21]
Output: 64


Example 3:

Input: nums = [1,2,3,4,5]
Output: 0


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 104
	1 &lt;= nums[i] &lt;= 105


import math 
class Solution:
    def sumFourDivisors(self, nums: List[int]) -> int:
        s=0
        for i in nums:
            r=i+1
            c=2
            for j in range(2, int(math.sqrt(i))+1):
                if i%j==0:
                    if (i / j == j) :
                        c+=1
                        r+=j
                    else :
                        c+=2
                        r+=j+int(i/j)
            print(c, r)
            if c==4:
                s+=r
        return s
class Solution {
    public int sumFourDivisors(int[] nums) {
        int res = 0;
        for(int val : nums){
            int sum = 0;
            int count = 0;
            for(int i=1;i*i <= val;i++){
                if(val % i == 0){
                    sum += i;
                    count++;
                    if(i != val/i){
                        sum += val/i;
                        count++;
                    }
                }
            }
            if(count == 4){
                res += sum;
            }
        }
        return res;
    }
}
class Solution {
public:
    int sumFourDivisors(vector<int>& nums) {
        int n = nums.size();
        int sum = 0,cnt=0,temp=0;
        for(int i=0;i<n;i++){
            
            int x = nums[i];
            int sq = sqrt(x);
            
            for(int j=1;j<=sq;j++){
                if(x%j==0){
                    cnt+=2; temp += (j+x/j);
                    
                    if(j==x/j){
                        cnt--; temp-=j;
                    }
                    
                    if(cnt>4)
                        break;
                }
            }
            if(cnt==4){
                sum += temp;
            }
            temp=0; cnt=0;
        }
        return sum;
    }
};
var sumFourDivisors = function(nums) {
    let check = (num) => {
        let divs = [num]; // init the array with the number itself
        let orig = num;
        num = num >> 1; // divide in half to avoid checking too many numbers
        while (num > 0) {
            if (orig % num === 0) divs.push(num);
            num--;
            if (divs.length > 4) return 0;
        }
        if (divs.length === 4) {
            return divs.reduce((a, b) => a + b, 0);
        }
        return 0;
    }
    
    let total = 0;
    
    for (let num of nums) {
        total += check(num);
    }
    
    return total;
};
Four Divisors